From 7924d1fc1850d454586da52d53ffa8ca3814985c Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 17 Sep 2021 13:31:11 +0100 Subject: [PATCH] Upgrade to Flyway 7.15.0 Closes gh-28049 --- .../flyway/FlywayAutoConfiguration.java | 7 +++ .../flyway/FlywayProperties.java | 44 +++++++++++++++++++ ...itional-spring-configuration-metadata.json | 12 +++++ .../flyway/FlywayPropertiesTests.java | 7 ++- .../spring-boot-dependencies/build.gradle | 2 +- 5 files changed, 70 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 19bcb9c01e..ceef7372c7 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 @@ -180,6 +180,9 @@ public class FlywayAutoConfiguration { map.from(locations).to(configuration::locations); map.from(properties.getEncoding()).to(configuration::encoding); map.from(properties.getConnectRetries()).to(configuration::connectRetries); + // No method reference for compatibility with Flyway < 7.15 + map.from(properties.getConnectRetriesInterval()) + .to((interval) -> configuration.connectRetriesInterval((int) interval.getSeconds())); // No method reference for compatibility with Flyway 6.x map.from(properties.getLockRetryCount()) .to((lockRetryCount) -> configuration.lockRetryCount(lockRetryCount)); @@ -220,6 +223,10 @@ public class FlywayAutoConfiguration { map.from(properties.getInitSqls()).whenNot(CollectionUtils::isEmpty) .as((initSqls) -> StringUtils.collectionToDelimitedString(initSqls, "\n")) .to(configuration::initSql); + map.from(properties.getScriptPlaceholderPrefix()) + .to((prefix) -> configuration.scriptPlaceholderPrefix(prefix)); + map.from(properties.getScriptPlaceholderPrefix()) + .to((suffix) -> configuration.scriptPlaceholderPrefix(suffix)); // Pro properties map.from(properties.getBatch()).to(configuration::batch); map.from(properties.getDryRunOutput()).to(configuration::dryRunOutput); 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 678c83a1cb..f34d4c0447 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 @@ -19,6 +19,8 @@ package org.springframework.boot.autoconfigure.flyway; import java.io.File; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.time.Duration; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -27,6 +29,7 @@ import java.util.Map; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; +import org.springframework.boot.convert.DurationUnit; /** * Configuration properties for Flyway database migrations. @@ -73,6 +76,13 @@ public class FlywayProperties { */ private int connectRetries; + /** + * Maximum time between retries when attempting to connect to the database. If a + * duration suffix is not specified, seconds will be used. + */ + @DurationUnit(ChronoUnit.SECONDS) + private Duration connectRetriesInterval; + /** * Maximum number of retries when trying to obtain a lock. */ @@ -365,6 +375,16 @@ public class FlywayProperties { */ private String stateScriptPrefix; + /** + * Prefix of placeholders in migration scripts. + */ + private String scriptPlaceholderPrefix; + + /** + * Suffix of placeholders in migration scripts. + */ + private String scriptPlaceholderSuffix; + public boolean isEnabled() { return this.enabled; } @@ -417,6 +437,14 @@ public class FlywayProperties { this.connectRetries = connectRetries; } + public Duration getConnectRetriesInterval() { + return this.connectRetriesInterval; + } + + public void setConnectRetriesInterval(Duration connectRetriesInterval) { + this.connectRetriesInterval = connectRetriesInterval; + } + public Integer getLockRetryCount() { return this.lockRetryCount; } @@ -868,4 +896,20 @@ public class FlywayProperties { this.stateScriptPrefix = stateScriptPrefix; } + public String getScriptPlaceholderPrefix() { + return this.scriptPlaceholderPrefix; + } + + public void setScriptPlaceholderPrefix(String scriptPlaceholderPrefix) { + this.scriptPlaceholderPrefix = scriptPlaceholderPrefix; + } + + public String getScriptPlaceholderSuffix() { + return this.scriptPlaceholderSuffix; + } + + public void setScriptPlaceholderSuffix(String scriptPlaceholderSuffix) { + this.scriptPlaceholderSuffix = scriptPlaceholderSuffix; + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 5226554718..74146977bd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -860,6 +860,10 @@ "http://localhost:9200" ] }, + { + "name": "spring.flyway.connect-retries-interval", + "defaultValue": 120 + }, { "name": "spring.flyway.dry-run-output", "type": "java.io.OutputStream", @@ -887,6 +891,14 @@ "name": "spring.flyway.lock-retry-count", "defaultValue": 50 }, + { + "name": "spring.flyway.script-placeholder-prefix", + "defaultValue": "FP__" + }, + { + "name": "spring.flyway.script-placeholder-suffix", + "defaultValue": "__" + }, { "name": "spring.flyway.sql-migration-suffix", "type": "java.lang.String", 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 e43052170a..ba1cf88ef8 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,9 @@ class FlywayPropertiesTests { .isEqualTo(configuration.getLocations()); assertThat(properties.getEncoding()).isEqualTo(configuration.getEncoding()); assertThat(properties.getConnectRetries()).isEqualTo(configuration.getConnectRetries()); + // Can't assert connect retries interval as it is new in Flyway 7.15 + // Asserting hard-coded value in the metadata instead + assertThat(configuration.getConnectRetriesInterval()).isEqualTo(120); // Can't assert lock retry count default as it is new in Flyway 7.1 // Asserting hard-coded value in the metadata instead assertThat(configuration.getLockRetryCount()).isEqualTo(50); @@ -93,6 +96,8 @@ class FlywayPropertiesTests { assertThat(configuration.isValidateMigrationNaming()).isEqualTo(properties.isValidateMigrationNaming()); assertThat(configuration.isValidateOnMigrate()).isEqualTo(properties.isValidateOnMigrate()); assertThat(properties.getDetectEncoding()).isNull(); + assertThat(configuration.getScriptPlaceholderPrefix()).isEqualTo("FP__"); + assertThat(configuration.getScriptPlaceholderSuffix()).isEqualTo("__"); } @Test @@ -108,7 +113,7 @@ class FlywayPropertiesTests { ignoreProperties(configuration, "callbacks", "classLoader", "dataSource", "javaMigrations", "javaMigrationClassProvider", "resourceProvider", "resolvers"); // Properties we don't want to expose - ignoreProperties(configuration, "resolversAsClassNames", "callbacksAsClassNames", "apiExtensions"); + ignoreProperties(configuration, "resolversAsClassNames", "callbacksAsClassNames", "apiExtensions", "loggers"); // Handled by the conversion service ignoreProperties(configuration, "baselineVersionAsString", "encodingAsString", "locationsAsStrings", "targetAsString"); diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index f35e8739b8..d4b88cb7aa 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -309,7 +309,7 @@ bom { ] } } - library("Flyway", "7.13.0") { + library("Flyway", "7.15.0") { group("org.flywaydb") { modules = [ "flyway-core"