Commit a72da74c authored by Stephane Nicoll's avatar Stephane Nicoll

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
parents 59852340 05acfaa6
...@@ -175,6 +175,7 @@ public class FlywayAutoConfiguration { ...@@ -175,6 +175,7 @@ public class FlywayAutoConfiguration {
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
String[] locations = new LocationResolver(configuration.getDataSource()) String[] locations = new LocationResolver(configuration.getDataSource())
.resolveLocations(properties.getLocations()).toArray(new String[0]); .resolveLocations(properties.getLocations()).toArray(new String[0]);
configureFailOnMissingLocations(configuration, properties.isFailOnMissingLocations());
map.from(locations).to(configuration::locations); map.from(locations).to(configuration::locations);
map.from(properties.getEncoding()).to(configuration::encoding); map.from(properties.getEncoding()).to(configuration::encoding);
map.from(properties.getConnectRetries()).to(configuration::connectRetries); map.from(properties.getConnectRetries()).to(configuration::connectRetries);
...@@ -252,6 +253,23 @@ public class FlywayAutoConfiguration { ...@@ -252,6 +253,23 @@ public class FlywayAutoConfiguration {
map.from(properties.getVaultToken()).to((vaultToken) -> configuration.vaultToken(vaultToken)); map.from(properties.getVaultToken()).to((vaultToken) -> configuration.vaultToken(vaultToken));
map.from(properties.getVaultSecrets()).whenNot(List::isEmpty) map.from(properties.getVaultSecrets()).whenNot(List::isEmpty)
.to((vaultSecrets) -> configuration.vaultSecrets(vaultSecrets.toArray(new String[0]))); .to((vaultSecrets) -> configuration.vaultSecrets(vaultSecrets.toArray(new String[0])));
// No method reference for compatibility with Flyway < 7.8
map.from(properties.getIgnoreMigrationPatterns()).whenNot(List::isEmpty)
.to((ignoreMigrationPatterns) -> configuration
.ignoreMigrationPatterns(ignoreMigrationPatterns.toArray(new String[0])));
// No method reference for compatibility with Flyway version < 7.9
map.from(properties.getDetectEncoding())
.to((detectEncoding) -> configuration.detectEncoding(detectEncoding));
}
private void configureFailOnMissingLocations(FluentConfiguration configuration,
boolean failOnMissingLocations) {
try {
configuration.failOnMissingLocations(failOnMissingLocations);
}
catch (NoSuchMethodError ex) {
// Flyway < 7.9
}
} }
private void configureCreateSchemas(FluentConfiguration configuration, boolean createSchemas) { private void configureCreateSchemas(FluentConfiguration configuration, boolean createSchemas) {
......
...@@ -52,6 +52,11 @@ public class FlywayProperties { ...@@ -52,6 +52,11 @@ public class FlywayProperties {
@Deprecated @Deprecated
private boolean checkLocation = true; private boolean checkLocation = true;
/**
* Whether to fail if a location of migration scripts doesn't exist.
*/
private boolean failOnMissingLocations;
/** /**
* Locations of migrations scripts. Can contain the special "{vendor}" placeholder to * Locations of migrations scripts. Can contain the special "{vendor}" placeholder to
* use vendor-specific locations. * use vendor-specific locations.
...@@ -355,6 +360,18 @@ public class FlywayProperties { ...@@ -355,6 +360,18 @@ public class FlywayProperties {
*/ */
private List<String> vaultSecrets; private List<String> vaultSecrets;
/**
* Ignore migrations that match this comma-separated list of patterns when validating
* migrations. Requires Flyway Teams.
*/
private List<String> ignoreMigrationPatterns;
/**
* Whether to attempt to automatically detect SQL migration file encoding. Requires
* Flyway Teams.
*/
private Boolean detectEncoding;
public boolean isEnabled() { public boolean isEnabled() {
return this.enabled; return this.enabled;
} }
...@@ -375,6 +392,14 @@ public class FlywayProperties { ...@@ -375,6 +392,14 @@ public class FlywayProperties {
this.checkLocation = checkLocation; this.checkLocation = checkLocation;
} }
public boolean isFailOnMissingLocations() {
return this.failOnMissingLocations;
}
public void setFailOnMissingLocations(boolean failOnMissingLocations) {
this.failOnMissingLocations = failOnMissingLocations;
}
public List<String> getLocations() { public List<String> getLocations() {
return this.locations; return this.locations;
} }
...@@ -842,4 +867,20 @@ public class FlywayProperties { ...@@ -842,4 +867,20 @@ public class FlywayProperties {
this.vaultSecrets = vaultSecrets; this.vaultSecrets = vaultSecrets;
} }
public List<String> getIgnoreMigrationPatterns() {
return this.ignoreMigrationPatterns;
}
public void setIgnoreMigrationPatterns(List<String> ignoreMigrationPatterns) {
this.ignoreMigrationPatterns = ignoreMigrationPatterns;
}
public Boolean getDetectEncoding() {
return this.detectEncoding;
}
public void setDetectEncoding(final Boolean detectEncoding) {
this.detectEncoding = detectEncoding;
}
} }
...@@ -288,6 +288,7 @@ class FlywayAutoConfigurationTests { ...@@ -288,6 +288,7 @@ class FlywayAutoConfigurationTests {
} }
@Test @Test
@Deprecated
void checkLocationsAllMissing() { void checkLocationsAllMissing() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.locations:classpath:db/missing1,classpath:db/migration2") .withPropertyValues("spring.flyway.locations:classpath:db/missing1,classpath:db/migration2")
...@@ -299,6 +300,7 @@ class FlywayAutoConfigurationTests { ...@@ -299,6 +300,7 @@ class FlywayAutoConfigurationTests {
} }
@Test @Test
@Deprecated
void checkLocationsAllExist() { void checkLocationsAllExist() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.locations:classpath:db/changelog,classpath:db/migration") .withPropertyValues("spring.flyway.locations:classpath:db/changelog,classpath:db/migration")
...@@ -306,6 +308,7 @@ class FlywayAutoConfigurationTests { ...@@ -306,6 +308,7 @@ class FlywayAutoConfigurationTests {
} }
@Test @Test
@Deprecated
void checkLocationsAllExistWithImplicitClasspathPrefix() { void checkLocationsAllExistWithImplicitClasspathPrefix() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.locations:db/changelog,db/migration") .withPropertyValues("spring.flyway.locations:db/changelog,db/migration")
...@@ -313,12 +316,53 @@ class FlywayAutoConfigurationTests { ...@@ -313,12 +316,53 @@ class FlywayAutoConfigurationTests {
} }
@Test @Test
@Deprecated
void checkLocationsAllExistWithFilesystemPrefix() { void checkLocationsAllExistWithFilesystemPrefix() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.locations:filesystem:src/test/resources/db/migration") .withPropertyValues("spring.flyway.locations:filesystem:src/test/resources/db/migration")
.run((context) -> assertThat(context).hasNotFailed()); .run((context) -> assertThat(context).hasNotFailed());
} }
@Test
void failOnMissingLocationsAllMissing() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.check-location=false",
"spring.flyway.fail-on-missing-locations=true")
.withPropertyValues("spring.flyway.locations:classpath:db/missing1,classpath:db/migration2")
.run((context) -> {
assertThat(context).hasFailed();
assertThat(context).getFailure().isInstanceOf(BeanCreationException.class);
assertThat(context).getFailure().hasMessageContaining("Unable to resolve location");
});
}
@Test
void failOnMissingLocationsAllExist() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.check-location=false",
"spring.flyway.fail-on-missing-locations=true")
.withPropertyValues("spring.flyway.locations:classpath:db/changelog,classpath:db/migration")
.run((context) -> assertThat(context).hasNotFailed());
}
@Test
void failOnMissingLocationsAllExistWithImplicitClasspathPrefix() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.check-location=false",
"spring.flyway.fail-on-missing-locations=true")
.withPropertyValues("spring.flyway.locations:db/changelog,db/migration")
.run((context) -> assertThat(context).hasNotFailed());
}
@Test
void failOnMissingLocationsAllExistWithFilesystemPrefix() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.check-location=false",
"spring.flyway.fail-on-missing-locations=true")
.withPropertyValues("spring.flyway.locations:filesystem:src/test/resources/db/migration")
.run((context) -> assertThat(context).hasNotFailed());
}
@Test @Test
void customFlywayMigrationStrategy() { void customFlywayMigrationStrategy() {
this.contextRunner this.contextRunner
......
...@@ -48,6 +48,7 @@ class FlywayPropertiesTests { ...@@ -48,6 +48,7 @@ class FlywayPropertiesTests {
void defaultValuesAreConsistent() { void defaultValuesAreConsistent() {
FlywayProperties properties = new FlywayProperties(); FlywayProperties properties = new FlywayProperties();
Configuration configuration = new FluentConfiguration(); Configuration configuration = new FluentConfiguration();
assertThat(configuration.getFailOnMissingLocations()).isEqualTo(properties.isFailOnMissingLocations());
assertThat(properties.getLocations().stream().map(Location::new).toArray(Location[]::new)) assertThat(properties.getLocations().stream().map(Location::new).toArray(Location[]::new))
.isEqualTo(configuration.getLocations()); .isEqualTo(configuration.getLocations());
assertThat(properties.getEncoding()).isEqualTo(configuration.getEncoding()); assertThat(properties.getEncoding()).isEqualTo(configuration.getEncoding());
...@@ -91,6 +92,7 @@ class FlywayPropertiesTests { ...@@ -91,6 +92,7 @@ class FlywayPropertiesTests {
assertThat(configuration.isSkipDefaultResolvers()).isEqualTo(properties.isSkipDefaultResolvers()); assertThat(configuration.isSkipDefaultResolvers()).isEqualTo(properties.isSkipDefaultResolvers());
assertThat(configuration.isValidateMigrationNaming()).isEqualTo(properties.isValidateMigrationNaming()); assertThat(configuration.isValidateMigrationNaming()).isEqualTo(properties.isValidateMigrationNaming());
assertThat(configuration.isValidateOnMigrate()).isEqualTo(properties.isValidateOnMigrate()); assertThat(configuration.isValidateOnMigrate()).isEqualTo(properties.isValidateOnMigrate());
assertThat(properties.getDetectEncoding()).isNull();
} }
@Test @Test
...@@ -119,6 +121,8 @@ class FlywayPropertiesTests { ...@@ -119,6 +121,8 @@ class FlywayPropertiesTests {
ignoreProperties(configuration, "shouldCreateSchemas"); ignoreProperties(configuration, "shouldCreateSchemas");
// Getters for the DataSource settings rather than actual properties // Getters for the DataSource settings rather than actual properties
ignoreProperties(configuration, "password", "url", "user"); ignoreProperties(configuration, "password", "url", "user");
// Properties not exposed by Flyway
ignoreProperties(configuration, "failOnMissingTarget");
List<String> configurationKeys = new ArrayList<>(configuration.keySet()); List<String> configurationKeys = new ArrayList<>(configuration.keySet());
Collections.sort(configurationKeys); Collections.sort(configurationKeys);
List<String> propertiesKeys = new ArrayList<>(properties.keySet()); List<String> propertiesKeys = new ArrayList<>(properties.keySet());
......
...@@ -306,7 +306,7 @@ bom { ...@@ -306,7 +306,7 @@ bom {
] ]
} }
} }
library("Flyway", "7.7.3") { library("Flyway", "7.9.2") {
group("org.flywaydb") { group("org.flywaydb") {
modules = [ modules = [
"flyway-core" "flyway-core"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment