Skip to content

Commit a749855

Browse files
jebeaudetsnicoll
authored andcommitted
Allow indexed access of flyway.locations
This commit allows to use the `flyway.locations` in an indexed fashion (i.e. typically in YAML configuration). See spring-projectsgh-4973
1 parent 5ef6903 commit a749855

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ else if (this.flywayDataSource != null) {
114114
else {
115115
flyway.setDataSource(this.dataSource);
116116
}
117+
//Explicitly set locations because the getter doesn't return a mutable value
118+
flyway.setLocations(this.properties.getLocations().toArray(new String[0]));
117119
return flyway;
118120
}
119121

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.flyway;
1818

19+
import java.util.ArrayList;
1920
import java.util.Arrays;
2021
import java.util.Collections;
2122
import java.util.List;
@@ -39,7 +40,7 @@ public class FlywayProperties {
3940
/**
4041
* Locations of migrations scripts.
4142
*/
42-
private List<String> locations = Arrays.asList("db/migration");
43+
private List<String> locations = new ArrayList<String>(Arrays.asList("db/migration"));
4344

4445
/**
4546
* Check that migration scripts location exists.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public void defaultFlyway() throws Exception {
104104

105105
@Test
106106
public void overrideLocations() throws Exception {
107-
EnvironmentTestUtils.addEnvironment(this.context,
108-
"flyway.locations:classpath:db/changelog,classpath:db/migration");
107+
EnvironmentTestUtils.addEnvironment(this.context, "flyway.locations[0]:classpath:db/changelog",
108+
"flyway.locations[1]:classpath:db/migration");
109109
registerAndRefresh(EmbeddedDataSourceConfiguration.class,
110110
FlywayAutoConfiguration.class,
111111
PropertyPlaceholderAutoConfiguration.class);

0 commit comments

Comments
 (0)