mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Fix Flyway filesystem prefix location check
Co-authored-by: Andy Bell <andyrbell@gmail.com> Closes gh-13863
This commit is contained in:
parent
f1cf41f544
commit
7865233b16
@ -117,13 +117,17 @@ public class FlywayAutoConfiguration {
|
||||
|
||||
private boolean hasAtLeastOneLocation() {
|
||||
for (String location : this.properties.getLocations()) {
|
||||
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
|
||||
@ConfigurationProperties(prefix = "flyway")
|
||||
public Flyway flyway() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -153,7 +153,7 @@ public class FlywayAutoConfigurationTests {
|
||||
@Test
|
||||
public void changeLogDoesNotExist() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"flyway.locations:file:no-such-dir");
|
||||
"flyway.locations:filesystem:no-such-dir");
|
||||
this.thrown.expect(BeanCreationException.class);
|
||||
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
|
||||
FlywayAutoConfiguration.class,
|
||||
@ -192,6 +192,16 @@ public class FlywayAutoConfigurationTests {
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkLocationsAllExistWithImplicitFilesystemPrefix() {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"flyway.locations:filesystem:src/test/resources/db/migration",
|
||||
"flyway.check-location:true");
|
||||
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
|
||||
FlywayAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customFlywayMigrationStrategy() throws Exception {
|
||||
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
|
||||
|
@ -2246,8 +2246,18 @@ To automatically run Flyway database migrations on startup, add the
|
||||
|
||||
The migrations are scripts in the form `V<VERSION>__<NAME>.sql` (with `<VERSION>` an
|
||||
underscore-separated version, e.g. '`1`' or '`2_1`'). By default they live in a folder
|
||||
`classpath:db/migration` but you can modify that using `flyway.locations`. You can also
|
||||
add a special `{vendor}` placeholder to use vendor-specific scripts. Assume the following:
|
||||
`classpath:db/migration` but you can modify that using `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]
|
||||
----
|
||||
|
Loading…
Reference in New Issue
Block a user