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 24876af7acb..ccb26b84dec 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 @@ -195,13 +195,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 50738198533..8329c03d24e 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 @@ -189,7 +189,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() @@ -226,6 +226,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 3bbbe29d0fe..3022d8d285f 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 @@ -2207,8 +2207,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] ----