From 6c29b29bd5d734d925778a67dfc56cc02b330c08 Mon Sep 17 00:00:00 2001 From: Kedar Joshi Date: Fri, 26 Jun 2020 21:44:57 +0530 Subject: [PATCH] Upgrade to Flyway 6.5.0 and support createSchemas See gh-22120 --- .../flyway/FlywayAutoConfiguration.java | 10 ++++++++++ .../autoconfigure/flyway/FlywayProperties.java | 14 ++++++++++++++ .../flyway/FlywayPropertiesTests.java | 6 +++++- .../spring-boot-dependencies/build.gradle | 2 +- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index f155ed2c8c..f61328bf3c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -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 { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java index b1557e1444..81e3d15bb8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java @@ -74,6 +74,12 @@ public class FlywayProperties { */ private List 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; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayPropertiesTests.java index 1c23e3cb53..f48e107785 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayPropertiesTests.java @@ -53,6 +53,7 @@ class FlywayPropertiesTests { 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())) @@ -98,7 +99,8 @@ class FlywayPropertiesTests { 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 @@ -109,6 +111,8 @@ class FlywayPropertiesTests { ignoreProperties(properties, "initSqls"); // Handled as dryRunOutput ignoreProperties(configuration, "dryRunOutputAsFile", "dryRunOutputAsFileName"); + // Handled as createSchemas + ignoreProperties(configuration, "shouldCreateSchemas"); List configurationKeys = new ArrayList<>(configuration.keySet()); Collections.sort(configurationKeys); List propertiesKeys = new ArrayList<>(properties.keySet()); diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index 04e91a29dd..01270ae121 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -310,7 +310,7 @@ bom { ] } } - library("Flyway", "6.4.4") { + library("Flyway", "6.5.0") { group("org.flywaydb") { modules = [ "flyway-core"