Harmonize configuration of Flyway SQL Server extension

Closes gh-36440
pull/36422/head
Stephane Nicoll 1 year ago
parent fb640c04e7
commit 71406977c2

@ -141,6 +141,12 @@ public class FlywayAutoConfiguration {
return new PropertiesFlywayConnectionDetails(this.properties);
}
@Bean
@ConditionalOnClass(name = "org.flywaydb.database.sqlserver.SQLServerConfigurationExtension")
SqlServerFlywayConfigurationCustomizer sqlServerFlywayConfigurationCustomizer() {
return new SqlServerFlywayConfigurationCustomizer(this.properties);
}
@Bean
@ConditionalOnClass(name = "org.flywaydb.database.oracle.OracleConfigurationExtension")
OracleFlywayConfigurationCustomizer oracleFlywayConfigurationCustomizer() {
@ -267,10 +273,6 @@ public class FlywayAutoConfiguration {
map.from(properties.getJdbcProperties()).whenNot(Map::isEmpty).to(configuration::jdbcProperties);
map.from(properties.getKerberosConfigFile()).to(configuration::kerberosConfigFile);
map.from(properties.getOutputQueryResults()).to(configuration::outputQueryResults);
map.from(properties.getSqlServerKerberosLoginFile())
.whenNonNull()
.to((sqlServerKerberosLoginFile) -> configureSqlServerKerberosLoginFile(configuration,
sqlServerKerberosLoginFile));
map.from(properties.getSkipExecutingMigrations()).to(configuration::skipExecutingMigrations);
map.from(properties.getIgnoreMigrationPatterns())
.whenNot(List::isEmpty)
@ -289,14 +291,6 @@ public class FlywayAutoConfiguration {
}
}
private void configureSqlServerKerberosLoginFile(FluentConfiguration configuration,
String sqlServerKerberosLoginFile) {
SQLServerConfigurationExtension sqlServerConfigurationExtension = configuration.getPluginRegister()
.getPlugin(SQLServerConfigurationExtension.class);
Assert.state(sqlServerConfigurationExtension != null, "Flyway SQL Server extension missing");
sqlServerConfigurationExtension.getKerberos().getLogin().setFile(sqlServerKerberosLoginFile);
}
private void configureCallbacks(FluentConfiguration configuration, List<Callback> callbacks) {
if (!callbacks.isEmpty()) {
configuration.callbacks(callbacks.toArray(new Callback[0]));
@ -484,6 +478,31 @@ public class FlywayAutoConfiguration {
}
@Order(Ordered.HIGHEST_PRECEDENCE)
static final class SqlServerFlywayConfigurationCustomizer implements FlywayConfigurationCustomizer {
private final FlywayProperties properties;
SqlServerFlywayConfigurationCustomizer(FlywayProperties properties) {
this.properties = properties;
}
@Override
public void customize(FluentConfiguration configuration) {
ConfigurationExtensionMapper<SQLServerConfigurationExtension> map = new ConfigurationExtensionMapper<>(
PropertyMapper.get().alwaysApplyingWhenNonNull(), () -> {
SQLServerConfigurationExtension extension = configuration.getPluginRegister()
.getPlugin(SQLServerConfigurationExtension.class);
Assert.notNull(extension, "Flyway SQL Server extension missing");
return extension;
});
map.apply(this.properties.getSqlServerKerberosLoginFile(),
(extension, file) -> extension.getKerberos().getLogin().setFile(file));
}
}
static class ConfigurationExtensionMapper<T extends ConfigurationExtension> {
private final PropertyMapper map;

@ -52,6 +52,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.FlywayAutoConfigurationRuntimeHints;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.OracleFlywayConfigurationCustomizer;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.SqlServerFlywayConfigurationCustomizer;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails;
@ -732,6 +733,13 @@ class FlywayAutoConfigurationTests {
.run(validateFlywayTeamsPropertyOnly("outputQueryResults"));
}
@Test
void sqlServerExtensionIsNotLoadedByDefault() {
FluentConfiguration configuration = mock(FluentConfiguration.class);
new SqlServerFlywayConfigurationCustomizer(new FlywayProperties()).customize(configuration);
then(configuration).shouldHaveNoInteractions();
}
@Test
void sqlServerKerberosLoginFileIsCorrectlyMapped() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)

Loading…
Cancel
Save