Skip to content

Upgrade to Flyway 6.5 and support new create schemas property #22120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ private void configureProperties(FluentConfiguration configuration, FlywayProper
// 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));
Expand Down Expand Up @@ -221,6 +222,15 @@ private void configureProperties(FluentConfiguration configuration, FlywayProper
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -343,6 +349,14 @@ public void setSchemas(List<String> schemas) {
this.schemas = schemas;
}

public boolean isCreateSchemas() {
return this.createSchemas;
}

public void setCreateSchemas(boolean createSchemas) {
this.createSchemas = createSchemas;
}

public String getTable() {
return this.table;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void defaultValuesAreConsistent() {
assertThat(properties.getConnectRetries()).isEqualTo(configuration.getConnectRetries());
assertThat(properties.getDefaultSchema()).isEqualTo(configuration.getDefaultSchema());
assertThat(properties.getSchemas()).isEqualTo(Arrays.asList(configuration.getSchemas()));
assertThat(properties.isCreateSchemas()).isEqualTo(configuration.getCreateSchemas());
assertThat(properties.getTable()).isEqualTo(configuration.getTable());
assertThat(properties.getBaselineDescription()).isEqualTo(configuration.getBaselineDescription());
assertThat(MigrationVersion.fromVersion(properties.getBaselineVersion()))
Expand Down Expand Up @@ -98,7 +99,8 @@ void expectedPropertiesAreManaged() {
ignoreProperties(properties, "url", "user", "password", "enabled", "checkLocation", "createDataSource");

// High level object we can't set with properties
ignoreProperties(configuration, "callbacks", "classLoader", "dataSource", "javaMigrations", "resolvers");
ignoreProperties(configuration, "callbacks", "classLoader", "dataSource", "javaMigrations",
"javaMigrationClassProvider", "resourceProvider", "resolvers");
// Properties we don't want to expose
ignoreProperties(configuration, "resolversAsClassNames", "callbacksAsClassNames");
// Handled by the conversion service
Expand All @@ -109,6 +111,8 @@ void expectedPropertiesAreManaged() {
ignoreProperties(properties, "initSqls");
// Handled as dryRunOutput
ignoreProperties(configuration, "dryRunOutputAsFile", "dryRunOutputAsFileName");
// Handled as createSchemas
ignoreProperties(configuration, "shouldCreateSchemas");
List<String> configurationKeys = new ArrayList<>(configuration.keySet());
Collections.sort(configurationKeys);
List<String> propertiesKeys = new ArrayList<>(properties.keySet());
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-project/spring-boot-dependencies/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ bom {
]
}
}
library("Flyway", "6.4.4") {
library("Flyway", "6.5.0") {
group("org.flywaydb") {
modules = [
"flyway-core"
Expand Down