Skip to content

Commit 7865233

Browse files
committed
Fix Flyway filesystem prefix location check
Co-authored-by: Andy Bell <[email protected]> Closes gh-13863
1 parent f1cf41f commit 7865233

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,17 @@ public void checkLocationExists() {
117117

118118
private boolean hasAtLeastOneLocation() {
119119
for (String location : this.properties.getLocations()) {
120-
if (this.resourceLoader.getResource(location).exists()) {
120+
if (this.resourceLoader.getResource(normalizePrefix(location)).exists()) {
121121
return true;
122122
}
123123
}
124124
return false;
125125
}
126126

127+
private String normalizePrefix(String location) {
128+
return location.replace("filesystem:", "file:");
129+
}
130+
127131
@Bean
128132
@ConfigurationProperties(prefix = "flyway")
129133
public Flyway flyway() {

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -153,7 +153,7 @@ public void overrideSchemas() throws Exception {
153153
@Test
154154
public void changeLogDoesNotExist() throws Exception {
155155
EnvironmentTestUtils.addEnvironment(this.context,
156-
"flyway.locations:file:no-such-dir");
156+
"flyway.locations:filesystem:no-such-dir");
157157
this.thrown.expect(BeanCreationException.class);
158158
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
159159
FlywayAutoConfiguration.class,
@@ -192,6 +192,16 @@ public void checkLocationsAllExistWithImplicitClasspathPrefix() throws Exception
192192
PropertyPlaceholderAutoConfiguration.class);
193193
}
194194

195+
@Test
196+
public void checkLocationsAllExistWithImplicitFilesystemPrefix() {
197+
EnvironmentTestUtils.addEnvironment(this.context,
198+
"flyway.locations:filesystem:src/test/resources/db/migration",
199+
"flyway.check-location:true");
200+
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
201+
FlywayAutoConfiguration.class,
202+
PropertyPlaceholderAutoConfiguration.class);
203+
}
204+
195205
@Test
196206
public void customFlywayMigrationStrategy() throws Exception {
197207
registerAndRefresh(EmbeddedDataSourceConfiguration.class,

spring-boot-docs/src/main/asciidoc/howto.adoc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,8 +2246,18 @@ To automatically run Flyway database migrations on startup, add the
22462246

22472247
The migrations are scripts in the form `V<VERSION>__<NAME>.sql` (with `<VERSION>` an
22482248
underscore-separated version, e.g. '`1`' or '`2_1`'). By default they live in a folder
2249-
`classpath:db/migration` but you can modify that using `flyway.locations`. You can also
2250-
add a special `{vendor}` placeholder to use vendor-specific scripts. Assume the following:
2249+
`classpath:db/migration` but you can modify that using `flyway.locations`. This is a
2250+
comma-separated list of one or more `classpath:` or `filesystem:` locations. For example,
2251+
the following configuration would search for scripts in both the default classpath
2252+
location and the `/opt/migration` directory:
2253+
2254+
[source,properties,indent=0]
2255+
----
2256+
spring.flyway.locations=classpath:db/migration,filesystem:/opt/migration
2257+
----
2258+
2259+
You can also add a special `{vendor}` placeholder to use vendor-specific scripts. Assume
2260+
the following:
22512261

22522262
[source,properties,indent=0]
22532263
----

0 commit comments

Comments
 (0)