Upgrade to Flyway 6.5.0 and support createSchemas

See gh-22120
This commit is contained in:
Kedar Joshi
2020-06-26 21:44:57 +05:30
committed by Andy Wilkinson
parent f6400e95ee
commit 6c29b29bd5
4 changed files with 30 additions and 2 deletions

View File

@@ -178,6 +178,7 @@ public class FlywayAutoConfiguration {
// No method reference for compatibility with Flyway 5.x
map.from(properties.getDefaultSchema()).to((schema) -> configuration.defaultSchema(schema));
map.from(properties.getSchemas()).as(StringUtils::toStringArray).to(configuration::schemas);
configureCreateSchemas(configuration, properties.isCreateSchemas());
map.from(properties.getTable()).to(configuration::table);
// No method reference for compatibility with Flyway 5.x
map.from(properties.getTablespace()).whenNonNull().to((tablespace) -> configuration.tablespace(tablespace));
@@ -221,6 +222,15 @@ public class FlywayAutoConfiguration {
map.from(properties.getUndoSqlMigrationPrefix()).whenNonNull().to(configuration::undoSqlMigrationPrefix);
}
private void configureCreateSchemas(FluentConfiguration configuration, boolean createSchemas) {
try {
configuration.createSchemas(createSchemas);
}
catch (NoSuchMethodError ex) {
// Flyway < 6.5
}
}
private void configureValidateMigrationNaming(FluentConfiguration configuration,
boolean validateMigrationNaming) {
try {

View File

@@ -74,6 +74,12 @@ public class FlywayProperties {
*/
private List<String> schemas = new ArrayList<>();
/**
* Whether Flyway should attempt to create the schemas specified in the schemas
* property.
*/
private boolean createSchemas = true;
/**
* Name of the schema history table that will be used by Flyway.
*/
@@ -343,6 +349,14 @@ public class FlywayProperties {
this.schemas = schemas;
}
public boolean isCreateSchemas() {
return this.createSchemas;
}
public void setCreateSchemas(boolean createSchemas) {
this.createSchemas = createSchemas;
}
public String getTable() {
return this.table;
}