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 811184b432d..6d1bea6aa8e 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 @@ -176,13 +176,17 @@ public class FlywayAutoConfiguration { private boolean hasAtLeastOneLocation(String... locations) { for (String location : locations) { - if (this.resourceLoader.getResource(location).exists()) { + if (this.resourceLoader.getResource(normalizePrefix(location)).exists()) { return true; } } return false; } + private String normalizePrefix(String location) { + return location.replace("filesystem:", "file:"); + } + @Bean @ConditionalOnMissingBean public FlywayMigrationInitializer flywayInitializer(Flyway flyway) { 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 90f2e8b864c..2c79783d6b0 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 @@ -181,7 +181,7 @@ public class FlywayAutoConfigurationTests { @Test public void changeLogDoesNotExist() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) - .withPropertyValues("spring.flyway.locations:file:no-such-dir") + .withPropertyValues("spring.flyway.locations:filesystem:no-such-dir") .run((context) -> { assertThat(context).hasFailed(); assertThat(context).getFailure() @@ -218,6 +218,14 @@ public class FlywayAutoConfigurationTests { .run((context) -> assertThat(context).hasNotFailed()); } + @Test + public void checkLocationsAllExistWithFilesystemPrefix() { + this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) + .withPropertyValues( + "spring.flyway.locations:filesystem:src/test/resources/db/migration") + .run((context) -> assertThat(context).hasNotFailed()); + } + @Test public void customFlywayMigrationStrategy() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class, diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc index 04e02129cbf..3c3e238b3d9 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -2205,8 +2205,17 @@ To automatically run Flyway database migrations on startup, add the The migrations are scripts in the form `V__.sql` (with `` an underscore-separated version, such as '`1`' or '`2_1`'). By default, they are in a folder called `classpath:db/migration`, but you can modify that location by setting -`spring.flyway.locations`. You can also add a special `{vendor}` placeholder to use -vendor-specific scripts. Assume the following: +`spring.flyway.locations`. This is a comma-separated list of one or more `classpath:` +or `filesystem:` locations. For example, the following configuration would search for +scripts in both the default classpath location and the `/opt/migration` directory: + +[source,properties,indent=0] +---- + spring.flyway.locations=classpath:db/migration,filesystem:/opt/migration +---- + +You can also add a special `{vendor}` placeholder to use vendor-specific scripts. Assume +the following: [source,properties,indent=0] ----