Move Flyway configuration extension properties to dedicated namespace

This commit harmonizes the handling of ConfigurationExtension for
Flyway. The existing Oracle and SQLServer extensions are now mapped from
flway.oracle and flyway.sqlserver, respectively. The existing properties
have been deprecated in favor of the new location.

Closes gh-36444
This commit is contained in:
Stephane Nicoll 2023-07-18 16:09:26 +02:00
parent 8da706603e
commit c6e47b86d7
4 changed files with 194 additions and 49 deletions

View File

@ -52,6 +52,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.FlywayAutoConfigurationRuntimeHints;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration.FlywayDataSourceCondition;
import org.springframework.boot.autoconfigure.flyway.FlywayProperties.Oracle;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails;
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
@ -477,10 +478,11 @@ public class FlywayAutoConfiguration {
Assert.notNull(extension, "Flyway Oracle extension missing");
return extension;
});
map.apply(this.properties.getOracleSqlplus(), OracleConfigurationExtension::setSqlplus);
map.apply(this.properties.getOracleSqlplusWarn(), OracleConfigurationExtension::setSqlplusWarn);
map.apply(this.properties.getOracleWalletLocation(), OracleConfigurationExtension::setWalletLocation);
map.apply(this.properties.getOracleKerberosCacheFile(), OracleConfigurationExtension::setKerberosCacheFile);
Oracle oracle = this.properties.getOracle();
map.apply(oracle.getSqlplus(), OracleConfigurationExtension::setSqlplus);
map.apply(oracle.getSqlplusWarn(), OracleConfigurationExtension::setSqlplusWarn);
map.apply(oracle.getWalletLocation(), OracleConfigurationExtension::setWalletLocation);
map.apply(oracle.getKerberosCacheFile(), OracleConfigurationExtension::setKerberosCacheFile);
}
}
@ -528,7 +530,7 @@ public class FlywayAutoConfiguration {
return extension;
});
map.apply(this.properties.getSqlServerKerberosLoginFile(),
map.apply(this.properties.getSqlserver().getKerberosLoginFile(),
(extension, file) -> extension.getKerberos().getLogin().setFile(file));
}

View File

@ -28,6 +28,7 @@ import java.util.List;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
import org.springframework.boot.convert.DurationUnit;
/**
@ -295,17 +296,6 @@ public class FlywayProperties {
*/
private String licenseKey;
/**
* Whether to enable support for Oracle SQL*Plus commands. Requires Flyway Teams.
*/
private Boolean oracleSqlplus;
/**
* Whether to issue a warning rather than an error when a not-yet-supported Oracle
* SQL*Plus statement is encountered. Requires Flyway Teams.
*/
private Boolean oracleSqlplusWarn;
/**
* Whether to stream SQL migrations when executing them. Requires Flyway Teams.
*/
@ -332,28 +322,12 @@ public class FlywayProperties {
*/
private String kerberosConfigFile;
/**
* Path of the Oracle Kerberos cache file. Requires Flyway Teams.
*/
private String oracleKerberosCacheFile;
/**
* Location of the Oracle Wallet, used to sign in to the database automatically.
* Requires Flyway Teams.
*/
private String oracleWalletLocation;
/**
* Whether Flyway should output a table with the results of queries when executing
* migrations. Requires Flyway Teams.
*/
private Boolean outputQueryResults;
/**
* Path to the SQL Server Kerberos login file. Requires Flyway Teams.
*/
private String sqlServerKerberosLoginFile;
/**
* Whether Flyway should skip executing the contents of the migrations and only update
* the schema history table. Requires Flyway teams.
@ -372,8 +346,12 @@ public class FlywayProperties {
*/
private Boolean detectEncoding;
private final Oracle oracle = new Oracle();
private final Postgresql postgresql = new Postgresql();
private final Sqlserver sqlserver = new Sqlserver();
public boolean isEnabled() {
return this.enabled;
}
@ -758,28 +736,37 @@ public class FlywayProperties {
this.licenseKey = licenseKey;
}
@DeprecatedConfigurationProperty(replacement = "spring.flyway.oracle.sqlplus")
@Deprecated(since = "3.2.0", forRemoval = true)
public Boolean getOracleSqlplus() {
return this.oracleSqlplus;
return getOracle().getSqlplus();
}
@Deprecated(since = "3.2.0", forRemoval = true)
public void setOracleSqlplus(Boolean oracleSqlplus) {
this.oracleSqlplus = oracleSqlplus;
getOracle().setSqlplus(oracleSqlplus);
}
@DeprecatedConfigurationProperty(replacement = "spring.flyway.oracle.sqlplus-warn")
@Deprecated(since = "3.2.0", forRemoval = true)
public Boolean getOracleSqlplusWarn() {
return this.oracleSqlplusWarn;
return getOracle().getSqlplusWarn();
}
@Deprecated(since = "3.2.0", forRemoval = true)
public void setOracleSqlplusWarn(Boolean oracleSqlplusWarn) {
this.oracleSqlplusWarn = oracleSqlplusWarn;
getOracle().setSqlplusWarn(oracleSqlplusWarn);
}
@DeprecatedConfigurationProperty(replacement = "spring.flyway.oracle.wallet-location")
@Deprecated(since = "3.2.0", forRemoval = true)
public String getOracleWalletLocation() {
return this.oracleWalletLocation;
return getOracle().getWalletLocation();
}
@Deprecated(since = "3.2.0", forRemoval = true)
public void setOracleWalletLocation(String oracleWalletLocation) {
this.oracleWalletLocation = oracleWalletLocation;
getOracle().setWalletLocation(oracleWalletLocation);
}
public Boolean getStream() {
@ -822,12 +809,15 @@ public class FlywayProperties {
this.kerberosConfigFile = kerberosConfigFile;
}
@DeprecatedConfigurationProperty(replacement = "spring.flyway.oracle.kerberos-cache-file")
@Deprecated(since = "3.2.0", forRemoval = true)
public String getOracleKerberosCacheFile() {
return this.oracleKerberosCacheFile;
return getOracle().getKerberosCacheFile();
}
@Deprecated(since = "3.2.0", forRemoval = true)
public void setOracleKerberosCacheFile(String oracleKerberosCacheFile) {
this.oracleKerberosCacheFile = oracleKerberosCacheFile;
getOracle().setKerberosCacheFile(oracleKerberosCacheFile);
}
public Boolean getOutputQueryResults() {
@ -838,12 +828,15 @@ public class FlywayProperties {
this.outputQueryResults = outputQueryResults;
}
@DeprecatedConfigurationProperty(replacement = "spring.flyway.sqlserver.kerberos-login-file")
@Deprecated(since = "3.2.0", forRemoval = true)
public String getSqlServerKerberosLoginFile() {
return this.sqlServerKerberosLoginFile;
return getSqlserver().getKerberosLoginFile();
}
@Deprecated(since = "3.2.0", forRemoval = true)
public void setSqlServerKerberosLoginFile(String sqlServerKerberosLoginFile) {
this.sqlServerKerberosLoginFile = sqlServerKerberosLoginFile;
getSqlserver().setKerberosLoginFile(sqlServerKerberosLoginFile);
}
public Boolean getSkipExecutingMigrations() {
@ -870,10 +863,79 @@ public class FlywayProperties {
this.detectEncoding = detectEncoding;
}
public Oracle getOracle() {
return this.oracle;
}
public Postgresql getPostgresql() {
return this.postgresql;
}
public Sqlserver getSqlserver() {
return this.sqlserver;
}
/**
* {@code OracleConfigurationExtension} properties.
*/
public static class Oracle {
/**
* Whether to enable support for Oracle SQL*Plus commands. Requires Flyway Teams.
*/
private Boolean sqlplus;
/**
* Whether to issue a warning rather than an error when a not-yet-supported Oracle
* SQL*Plus statement is encountered. Requires Flyway Teams.
*/
private Boolean sqlplusWarn;
/**
* Path of the Oracle Kerberos cache file. Requires Flyway Teams.
*/
private String kerberosCacheFile;
/**
* Location of the Oracle Wallet, used to sign in to the database automatically.
* Requires Flyway Teams.
*/
private String walletLocation;
public Boolean getSqlplus() {
return this.sqlplus;
}
public void setSqlplus(Boolean sqlplus) {
this.sqlplus = sqlplus;
}
public Boolean getSqlplusWarn() {
return this.sqlplusWarn;
}
public void setSqlplusWarn(Boolean sqlplusWarn) {
this.sqlplusWarn = sqlplusWarn;
}
public String getKerberosCacheFile() {
return this.kerberosCacheFile;
}
public void setKerberosCacheFile(String kerberosCacheFile) {
this.kerberosCacheFile = kerberosCacheFile;
}
public String getWalletLocation() {
return this.walletLocation;
}
public void setWalletLocation(String walletLocation) {
this.walletLocation = walletLocation;
}
}
/**
* {@code PostgreSQLConfigurationExtension} properties.
*/
@ -895,4 +957,24 @@ public class FlywayProperties {
}
/**
* {@code SQLServerConfigurationExtension} properties.
*/
public static class Sqlserver {
/**
* Path to the SQL Server Kerberos login file. Requires Flyway Teams.
*/
private String kerberosLoginFile;
public String getKerberosLoginFile() {
return this.kerberosLoginFile;
}
public void setKerberosLoginFile(String kerberosLoginFile) {
this.kerberosLoginFile = kerberosLoginFile;
}
}
}

View File

@ -618,6 +618,19 @@ class FlywayAutoConfigurationTests {
@Test
void oracleSqlplusIsCorrectlyMapped() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.oracle.sqlplus=true")
.run((context) -> assertThat(context.getBean(Flyway.class)
.getConfiguration()
.getPluginRegister()
.getPlugin(OracleConfigurationExtension.class)
.getSqlplus()).isTrue());
}
@Test
@Deprecated(since = "3.2.0", forRemoval = true)
void oracleSqlplusIsCorrectlyMappedWithDeprecatedProperty() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.oracle-sqlplus=true")
.run((context) -> assertThat(context.getBean(Flyway.class)
@ -630,6 +643,18 @@ class FlywayAutoConfigurationTests {
@Test
void oracleSqlplusWarnIsCorrectlyMapped() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.oracle.sqlplus-warn=true")
.run((context) -> assertThat(context.getBean(Flyway.class)
.getConfiguration()
.getPluginRegister()
.getPlugin(OracleConfigurationExtension.class)
.getSqlplusWarn()).isTrue());
}
@Test
@Deprecated(since = "3.2.0", forRemoval = true)
void oracleSqlplusWarnIsCorrectlyMappedWithDeprecatedProperty() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.oracle-sqlplus-warn=true")
.run((context) -> assertThat(context.getBean(Flyway.class)
@ -641,6 +666,18 @@ class FlywayAutoConfigurationTests {
@Test
void oracleWallerLocationIsCorrectlyMapped() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.oracle.wallet-location=/tmp/my.wallet")
.run((context) -> assertThat(context.getBean(Flyway.class)
.getConfiguration()
.getPluginRegister()
.getPlugin(OracleConfigurationExtension.class)
.getWalletLocation()).isEqualTo("/tmp/my.wallet"));
}
@Test
@Deprecated(since = "3.2.0", forRemoval = true)
void oracleWallerLocationIsCorrectlyMappedWithDeprecatedProperty() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.oracle-wallet-location=/tmp/my.wallet")
.run((context) -> assertThat(context.getBean(Flyway.class)
@ -652,6 +689,18 @@ class FlywayAutoConfigurationTests {
@Test
void oracleKerberosCacheFileIsCorrectlyMapped() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.oracle.kerberos-cache-file=/tmp/cache")
.run((context) -> assertThat(context.getBean(Flyway.class)
.getConfiguration()
.getPluginRegister()
.getPlugin(OracleConfigurationExtension.class)
.getKerberosCacheFile()).isEqualTo("/tmp/cache"));
}
@Test
@Deprecated(since = "3.2.0", forRemoval = true)
void oracleKerberosCacheFileIsCorrectlyMappedWithDeprecatedProperty() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.oracle-kerberos-cache-file=/tmp/cache")
.run((context) -> assertThat(context.getBean(Flyway.class)
@ -762,6 +811,20 @@ class FlywayAutoConfigurationTests {
@Test
void sqlServerKerberosLoginFileIsCorrectlyMapped() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.sqlserver.kerberos-login-file=/tmp/config")
.run((context) -> assertThat(context.getBean(Flyway.class)
.getConfiguration()
.getPluginRegister()
.getPlugin(SQLServerConfigurationExtension.class)
.getKerberos()
.getLogin()
.getFile()).isEqualTo("/tmp/config"));
}
@Test
@Deprecated(since = "3.2.0", forRemoval = true)
void sqlServerKerberosLoginFileIsCorrectlyMappedWithDeprecatedProperty() {
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
.withPropertyValues("spring.flyway.sql-server-kerberos-login-file=/tmp/config")
.run((context) -> assertThat(context.getBean(Flyway.class)

View File

@ -109,13 +109,11 @@ class FlywayPropertiesTests {
PropertyAccessorFactory.forBeanPropertyAccess(new ClassicConfiguration()));
// Properties specific settings
ignoreProperties(properties, "url", "driverClassName", "user", "password", "enabled");
// Property that moved to a separate Oracle plugin
ignoreProperties(properties, "oracleSqlplus", "oracleSqlplusWarn", "oracleKerberosCacheFile",
"oracleWalletLocation");
// Postgresql extension
ignoreProperties(properties, "postgresql");
// Property that moved to a separate SQL plugin
ignoreProperties(properties, "sqlServerKerberosLoginFile");
// Deprecated properties
ignoreProperties(properties, "oracleKerberosCacheFile", "oracleSqlplus", "oracleSqlplusWarn",
"oracleWalletLocation", "sqlServerKerberosLoginFile");
// Properties that are managed by specific extensions
ignoreProperties(properties, "oracle", "postgresql", "sqlserver");
// High level object we can't set with properties
ignoreProperties(configuration, "callbacks", "classLoader", "dataSource", "javaMigrations",
"javaMigrationClassProvider", "pluginRegister", "resourceProvider", "resolvers");