Skip to content

Commit 6c29b29

Browse files
kedar-joshiwilkinsona
authored andcommitted
Upgrade to Flyway 6.5.0 and support createSchemas
See gh-22120
1 parent f6400e9 commit 6c29b29

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ private void configureProperties(FluentConfiguration configuration, FlywayProper
178178
// No method reference for compatibility with Flyway 5.x
179179
map.from(properties.getDefaultSchema()).to((schema) -> configuration.defaultSchema(schema));
180180
map.from(properties.getSchemas()).as(StringUtils::toStringArray).to(configuration::schemas);
181+
configureCreateSchemas(configuration, properties.isCreateSchemas());
181182
map.from(properties.getTable()).to(configuration::table);
182183
// No method reference for compatibility with Flyway 5.x
183184
map.from(properties.getTablespace()).whenNonNull().to((tablespace) -> configuration.tablespace(tablespace));
@@ -221,6 +222,15 @@ private void configureProperties(FluentConfiguration configuration, FlywayProper
221222
map.from(properties.getUndoSqlMigrationPrefix()).whenNonNull().to(configuration::undoSqlMigrationPrefix);
222223
}
223224

225+
private void configureCreateSchemas(FluentConfiguration configuration, boolean createSchemas) {
226+
try {
227+
configuration.createSchemas(createSchemas);
228+
}
229+
catch (NoSuchMethodError ex) {
230+
// Flyway < 6.5
231+
}
232+
}
233+
224234
private void configureValidateMigrationNaming(FluentConfiguration configuration,
225235
boolean validateMigrationNaming) {
226236
try {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ public class FlywayProperties {
7474
*/
7575
private List<String> schemas = new ArrayList<>();
7676

77+
/**
78+
* Whether Flyway should attempt to create the schemas specified in the schemas
79+
* property.
80+
*/
81+
private boolean createSchemas = true;
82+
7783
/**
7884
* Name of the schema history table that will be used by Flyway.
7985
*/
@@ -343,6 +349,14 @@ public void setSchemas(List<String> schemas) {
343349
this.schemas = schemas;
344350
}
345351

352+
public boolean isCreateSchemas() {
353+
return this.createSchemas;
354+
}
355+
356+
public void setCreateSchemas(boolean createSchemas) {
357+
this.createSchemas = createSchemas;
358+
}
359+
346360
public String getTable() {
347361
return this.table;
348362
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void defaultValuesAreConsistent() {
5353
assertThat(properties.getConnectRetries()).isEqualTo(configuration.getConnectRetries());
5454
assertThat(properties.getDefaultSchema()).isEqualTo(configuration.getDefaultSchema());
5555
assertThat(properties.getSchemas()).isEqualTo(Arrays.asList(configuration.getSchemas()));
56+
assertThat(properties.isCreateSchemas()).isEqualTo(configuration.getCreateSchemas());
5657
assertThat(properties.getTable()).isEqualTo(configuration.getTable());
5758
assertThat(properties.getBaselineDescription()).isEqualTo(configuration.getBaselineDescription());
5859
assertThat(MigrationVersion.fromVersion(properties.getBaselineVersion()))
@@ -98,7 +99,8 @@ void expectedPropertiesAreManaged() {
9899
ignoreProperties(properties, "url", "user", "password", "enabled", "checkLocation", "createDataSource");
99100

100101
// High level object we can't set with properties
101-
ignoreProperties(configuration, "callbacks", "classLoader", "dataSource", "javaMigrations", "resolvers");
102+
ignoreProperties(configuration, "callbacks", "classLoader", "dataSource", "javaMigrations",
103+
"javaMigrationClassProvider", "resourceProvider", "resolvers");
102104
// Properties we don't want to expose
103105
ignoreProperties(configuration, "resolversAsClassNames", "callbacksAsClassNames");
104106
// Handled by the conversion service
@@ -109,6 +111,8 @@ void expectedPropertiesAreManaged() {
109111
ignoreProperties(properties, "initSqls");
110112
// Handled as dryRunOutput
111113
ignoreProperties(configuration, "dryRunOutputAsFile", "dryRunOutputAsFileName");
114+
// Handled as createSchemas
115+
ignoreProperties(configuration, "shouldCreateSchemas");
112116
List<String> configurationKeys = new ArrayList<>(configuration.keySet());
113117
Collections.sort(configurationKeys);
114118
List<String> propertiesKeys = new ArrayList<>(properties.keySet());

spring-boot-project/spring-boot-dependencies/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ bom {
310310
]
311311
}
312312
}
313-
library("Flyway", "6.4.4") {
313+
library("Flyway", "6.5.0") {
314314
group("org.flywaydb") {
315315
modules = [
316316
"flyway-core"

0 commit comments

Comments
 (0)