From 05acfaa6908ab9fc36337a62add29d5a448ac7e1 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 31 May 2021 08:45:27 +0200 Subject: [PATCH] Polish "Upgrade to Flyway 7.9.2" See gh-26456 --- .../flyway/FlywayAutoConfiguration.java | 2 +- .../flyway/FlywayProperties.java | 7 ++- .../flyway/FlywayAutoConfigurationTests.java | 44 +++++++++++++++++++ 3 files changed, 48 insertions(+), 5 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 0e91053fef..adcbd84a49 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 @@ -258,7 +258,7 @@ public class FlywayAutoConfiguration { .to((ignoreMigrationPatterns) -> configuration .ignoreMigrationPatterns(ignoreMigrationPatterns.toArray(new String[0]))); // No method reference for compatibility with Flyway version < 7.9 - map.from(properties.getDetectEncoding()).whenNonNull() + map.from(properties.getDetectEncoding()) .to((detectEncoding) -> configuration.detectEncoding(detectEncoding)); } 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 1982eab1f4..61087b5248 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 @@ -53,8 +53,7 @@ public class FlywayProperties { private boolean checkLocation = true; /** - * Whether Flyway should fail if a location specified in the flyway.locations option - * doesn't exist. + * Whether to fail if a location of migration scripts doesn't exist. */ private boolean failOnMissingLocations; @@ -368,8 +367,8 @@ public class FlywayProperties { private List ignoreMigrationPatterns; /** - * Whether Flyway should try to automatically detect SQL migration file encoding. - * Requires Flyway Teams. + * Whether to attempt to automatically detect SQL migration file encoding. Requires + * Flyway Teams. */ private Boolean detectEncoding; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java index 0a39f1ec26..ca90fc991f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java @@ -288,6 +288,7 @@ class FlywayAutoConfigurationTests { } @Test + @Deprecated void checkLocationsAllMissing() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.flyway.locations:classpath:db/missing1,classpath:db/migration2") @@ -299,6 +300,7 @@ class FlywayAutoConfigurationTests { } @Test + @Deprecated void checkLocationsAllExist() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.flyway.locations:classpath:db/changelog,classpath:db/migration") @@ -306,6 +308,7 @@ class FlywayAutoConfigurationTests { } @Test + @Deprecated void checkLocationsAllExistWithImplicitClasspathPrefix() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.flyway.locations:db/changelog,db/migration") @@ -313,12 +316,53 @@ class FlywayAutoConfigurationTests { } @Test + @Deprecated void checkLocationsAllExistWithFilesystemPrefix() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.flyway.locations:filesystem:src/test/resources/db/migration") .run((context) -> assertThat(context).hasNotFailed()); } + @Test + void failOnMissingLocationsAllMissing() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) + .withPropertyValues("spring.flyway.check-location=false", + "spring.flyway.fail-on-missing-locations=true") + .withPropertyValues("spring.flyway.locations:classpath:db/missing1,classpath:db/migration2") + .run((context) -> { + assertThat(context).hasFailed(); + assertThat(context).getFailure().isInstanceOf(BeanCreationException.class); + assertThat(context).getFailure().hasMessageContaining("Unable to resolve location"); + }); + } + + @Test + void failOnMissingLocationsAllExist() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) + .withPropertyValues("spring.flyway.check-location=false", + "spring.flyway.fail-on-missing-locations=true") + .withPropertyValues("spring.flyway.locations:classpath:db/changelog,classpath:db/migration") + .run((context) -> assertThat(context).hasNotFailed()); + } + + @Test + void failOnMissingLocationsAllExistWithImplicitClasspathPrefix() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) + .withPropertyValues("spring.flyway.check-location=false", + "spring.flyway.fail-on-missing-locations=true") + .withPropertyValues("spring.flyway.locations:db/changelog,db/migration") + .run((context) -> assertThat(context).hasNotFailed()); + } + + @Test + void failOnMissingLocationsAllExistWithFilesystemPrefix() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) + .withPropertyValues("spring.flyway.check-location=false", + "spring.flyway.fail-on-missing-locations=true") + .withPropertyValues("spring.flyway.locations:filesystem:src/test/resources/db/migration") + .run((context) -> assertThat(context).hasNotFailed()); + } + @Test void customFlywayMigrationStrategy() { this.contextRunner