Skip to content

Commit a72da74

Browse files
committed
Merge pull request #26456 from kedar-joshi
* pr/26456: Polish "Upgrade to Flyway 7.9.2" Upgrade to Flyway 7.9.2 Closes gh-26456
2 parents 5985234 + 05acfaa commit a72da74

File tree

5 files changed

+108
-1
lines changed

5 files changed

+108
-1
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ private void configureProperties(FluentConfiguration configuration, FlywayProper
175175
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
176176
String[] locations = new LocationResolver(configuration.getDataSource())
177177
.resolveLocations(properties.getLocations()).toArray(new String[0]);
178+
configureFailOnMissingLocations(configuration, properties.isFailOnMissingLocations());
178179
map.from(locations).to(configuration::locations);
179180
map.from(properties.getEncoding()).to(configuration::encoding);
180181
map.from(properties.getConnectRetries()).to(configuration::connectRetries);
@@ -252,6 +253,23 @@ private void configureProperties(FluentConfiguration configuration, FlywayProper
252253
map.from(properties.getVaultToken()).to((vaultToken) -> configuration.vaultToken(vaultToken));
253254
map.from(properties.getVaultSecrets()).whenNot(List::isEmpty)
254255
.to((vaultSecrets) -> configuration.vaultSecrets(vaultSecrets.toArray(new String[0])));
256+
// No method reference for compatibility with Flyway < 7.8
257+
map.from(properties.getIgnoreMigrationPatterns()).whenNot(List::isEmpty)
258+
.to((ignoreMigrationPatterns) -> configuration
259+
.ignoreMigrationPatterns(ignoreMigrationPatterns.toArray(new String[0])));
260+
// No method reference for compatibility with Flyway version < 7.9
261+
map.from(properties.getDetectEncoding())
262+
.to((detectEncoding) -> configuration.detectEncoding(detectEncoding));
263+
}
264+
265+
private void configureFailOnMissingLocations(FluentConfiguration configuration,
266+
boolean failOnMissingLocations) {
267+
try {
268+
configuration.failOnMissingLocations(failOnMissingLocations);
269+
}
270+
catch (NoSuchMethodError ex) {
271+
// Flyway < 7.9
272+
}
255273
}
256274

257275
private void configureCreateSchemas(FluentConfiguration configuration, boolean createSchemas) {

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public class FlywayProperties {
5252
@Deprecated
5353
private boolean checkLocation = true;
5454

55+
/**
56+
* Whether to fail if a location of migration scripts doesn't exist.
57+
*/
58+
private boolean failOnMissingLocations;
59+
5560
/**
5661
* Locations of migrations scripts. Can contain the special "{vendor}" placeholder to
5762
* use vendor-specific locations.
@@ -355,6 +360,18 @@ public class FlywayProperties {
355360
*/
356361
private List<String> vaultSecrets;
357362

363+
/**
364+
* Ignore migrations that match this comma-separated list of patterns when validating
365+
* migrations. Requires Flyway Teams.
366+
*/
367+
private List<String> ignoreMigrationPatterns;
368+
369+
/**
370+
* Whether to attempt to automatically detect SQL migration file encoding. Requires
371+
* Flyway Teams.
372+
*/
373+
private Boolean detectEncoding;
374+
358375
public boolean isEnabled() {
359376
return this.enabled;
360377
}
@@ -375,6 +392,14 @@ public void setCheckLocation(boolean checkLocation) {
375392
this.checkLocation = checkLocation;
376393
}
377394

395+
public boolean isFailOnMissingLocations() {
396+
return this.failOnMissingLocations;
397+
}
398+
399+
public void setFailOnMissingLocations(boolean failOnMissingLocations) {
400+
this.failOnMissingLocations = failOnMissingLocations;
401+
}
402+
378403
public List<String> getLocations() {
379404
return this.locations;
380405
}
@@ -842,4 +867,20 @@ public void setVaultSecrets(List<String> vaultSecrets) {
842867
this.vaultSecrets = vaultSecrets;
843868
}
844869

870+
public List<String> getIgnoreMigrationPatterns() {
871+
return this.ignoreMigrationPatterns;
872+
}
873+
874+
public void setIgnoreMigrationPatterns(List<String> ignoreMigrationPatterns) {
875+
this.ignoreMigrationPatterns = ignoreMigrationPatterns;
876+
}
877+
878+
public Boolean getDetectEncoding() {
879+
return this.detectEncoding;
880+
}
881+
882+
public void setDetectEncoding(final Boolean detectEncoding) {
883+
this.detectEncoding = detectEncoding;
884+
}
885+
845886
}

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ void changeLogDoesNotExist() {
288288
}
289289

290290
@Test
291+
@Deprecated
291292
void checkLocationsAllMissing() {
292293
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
293294
.withPropertyValues("spring.flyway.locations:classpath:db/missing1,classpath:db/migration2")
@@ -299,26 +300,69 @@ void checkLocationsAllMissing() {
299300
}
300301

301302
@Test
303+
@Deprecated
302304
void checkLocationsAllExist() {
303305
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
304306
.withPropertyValues("spring.flyway.locations:classpath:db/changelog,classpath:db/migration")
305307
.run((context) -> assertThat(context).hasNotFailed());
306308
}
307309

308310
@Test
311+
@Deprecated
309312
void checkLocationsAllExistWithImplicitClasspathPrefix() {
310313
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
311314
.withPropertyValues("spring.flyway.locations:db/changelog,db/migration")
312315
.run((context) -> assertThat(context).hasNotFailed());
313316
}
314317

315318
@Test
319+
@Deprecated
316320
void checkLocationsAllExistWithFilesystemPrefix() {
317321
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
318322
.withPropertyValues("spring.flyway.locations:filesystem:src/test/resources/db/migration")
319323
.run((context) -> assertThat(context).hasNotFailed());
320324
}
321325

326+
@Test
327+
void failOnMissingLocationsAllMissing() {
328+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
329+
.withPropertyValues("spring.flyway.check-location=false",
330+
"spring.flyway.fail-on-missing-locations=true")
331+
.withPropertyValues("spring.flyway.locations:classpath:db/missing1,classpath:db/migration2")
332+
.run((context) -> {
333+
assertThat(context).hasFailed();
334+
assertThat(context).getFailure().isInstanceOf(BeanCreationException.class);
335+
assertThat(context).getFailure().hasMessageContaining("Unable to resolve location");
336+
});
337+
}
338+
339+
@Test
340+
void failOnMissingLocationsAllExist() {
341+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
342+
.withPropertyValues("spring.flyway.check-location=false",
343+
"spring.flyway.fail-on-missing-locations=true")
344+
.withPropertyValues("spring.flyway.locations:classpath:db/changelog,classpath:db/migration")
345+
.run((context) -> assertThat(context).hasNotFailed());
346+
}
347+
348+
@Test
349+
void failOnMissingLocationsAllExistWithImplicitClasspathPrefix() {
350+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
351+
.withPropertyValues("spring.flyway.check-location=false",
352+
"spring.flyway.fail-on-missing-locations=true")
353+
.withPropertyValues("spring.flyway.locations:db/changelog,db/migration")
354+
.run((context) -> assertThat(context).hasNotFailed());
355+
}
356+
357+
@Test
358+
void failOnMissingLocationsAllExistWithFilesystemPrefix() {
359+
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
360+
.withPropertyValues("spring.flyway.check-location=false",
361+
"spring.flyway.fail-on-missing-locations=true")
362+
.withPropertyValues("spring.flyway.locations:filesystem:src/test/resources/db/migration")
363+
.run((context) -> assertThat(context).hasNotFailed());
364+
}
365+
322366
@Test
323367
void customFlywayMigrationStrategy() {
324368
this.contextRunner

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class FlywayPropertiesTests {
4848
void defaultValuesAreConsistent() {
4949
FlywayProperties properties = new FlywayProperties();
5050
Configuration configuration = new FluentConfiguration();
51+
assertThat(configuration.getFailOnMissingLocations()).isEqualTo(properties.isFailOnMissingLocations());
5152
assertThat(properties.getLocations().stream().map(Location::new).toArray(Location[]::new))
5253
.isEqualTo(configuration.getLocations());
5354
assertThat(properties.getEncoding()).isEqualTo(configuration.getEncoding());
@@ -91,6 +92,7 @@ void defaultValuesAreConsistent() {
9192
assertThat(configuration.isSkipDefaultResolvers()).isEqualTo(properties.isSkipDefaultResolvers());
9293
assertThat(configuration.isValidateMigrationNaming()).isEqualTo(properties.isValidateMigrationNaming());
9394
assertThat(configuration.isValidateOnMigrate()).isEqualTo(properties.isValidateOnMigrate());
95+
assertThat(properties.getDetectEncoding()).isNull();
9496
}
9597

9698
@Test
@@ -119,6 +121,8 @@ void expectedPropertiesAreManaged() {
119121
ignoreProperties(configuration, "shouldCreateSchemas");
120122
// Getters for the DataSource settings rather than actual properties
121123
ignoreProperties(configuration, "password", "url", "user");
124+
// Properties not exposed by Flyway
125+
ignoreProperties(configuration, "failOnMissingTarget");
122126
List<String> configurationKeys = new ArrayList<>(configuration.keySet());
123127
Collections.sort(configurationKeys);
124128
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
@@ -306,7 +306,7 @@ bom {
306306
]
307307
}
308308
}
309-
library("Flyway", "7.7.3") {
309+
library("Flyway", "7.9.2") {
310310
group("org.flywaydb") {
311311
modules = [
312312
"flyway-core"

0 commit comments

Comments
 (0)