Add configuration properties for Flyway 7's new config options
Closes gh-23579
This commit is contained in:
		
							parent
							
								
									847aecf621
								
							
						
					
					
						commit
						1d610fe1c8
					
				| 
						 | 
				
			
			@ -21,6 +21,7 @@ import java.util.Collection;
 | 
			
		|||
import java.util.Collections;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.function.Supplier;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
| 
						 | 
				
			
			@ -220,6 +221,20 @@ public class FlywayAutoConfiguration {
 | 
			
		|||
					.to((oracleSqlplusWarn) -> configuration.oracleSqlplusWarn(oracleSqlplusWarn));
 | 
			
		||||
			map.from(properties.getStream()).whenNonNull().to(configuration::stream);
 | 
			
		||||
			map.from(properties.getUndoSqlMigrationPrefix()).whenNonNull().to(configuration::undoSqlMigrationPrefix);
 | 
			
		||||
			// No method reference for compatibility with Flyway 6.x
 | 
			
		||||
			map.from(properties.getCherryPick()).whenNonNull().to((cherryPick) -> configuration.cherryPick(cherryPick));
 | 
			
		||||
			// No method reference for compatibility with Flyway 6.x
 | 
			
		||||
			map.from(properties.getJdbcProperties()).whenNot(Map::isEmpty)
 | 
			
		||||
					.to((jdbcProperties) -> configuration.jdbcProperties(jdbcProperties));
 | 
			
		||||
			// No method reference for compatibility with Flyway 6.x
 | 
			
		||||
			map.from(properties.getOracleKerberosCacheFile()).whenNonNull()
 | 
			
		||||
					.to((cacheFile) -> configuration.orackeKerberosCacheFile(cacheFile));
 | 
			
		||||
			// No method reference for compatibility with Flyway 6.x
 | 
			
		||||
			map.from(properties.getOracleKerberosConfigFile()).whenNonNull()
 | 
			
		||||
					.to((configFile) -> configuration.orackeKerberosConfigFile(configFile));
 | 
			
		||||
			// No method reference for compatibility with Flyway 6.x
 | 
			
		||||
			map.from(properties.getSkipExecutingMigrations()).whenNonNull()
 | 
			
		||||
					.to((skipExecutingMigrations) -> configuration.skipExecutingMigrations(skipExecutingMigrations));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private void configureCreateSchemas(FluentConfiguration configuration, boolean createSchemas) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -290,6 +290,33 @@ public class FlywayProperties {
 | 
			
		|||
	 */
 | 
			
		||||
	private String undoSqlMigrationPrefix;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Migrations that Flyway should consider when migrating or undoing. When empty all
 | 
			
		||||
	 * available migrations are considered. Requires Flyway Teams.
 | 
			
		||||
	 */
 | 
			
		||||
	private String[] cherryPick;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Properties to pass to the JDBC driver. Requires Flyway Teams.
 | 
			
		||||
	 */
 | 
			
		||||
	private Map<String, String> jdbcProperties = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Path of the Oracle Kerberos cache file. Requires Flyway Teams.
 | 
			
		||||
	 */
 | 
			
		||||
	private String oracleKerberosCacheFile;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Path of the Oracle Kerberos config file. Requires Flyway Teams.
 | 
			
		||||
	 */
 | 
			
		||||
	private String oracleKerberosConfigFile;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Whether Flyway should skip executing the contents of the migrations and only update
 | 
			
		||||
	 * the schema history table. Requires Flyway teams.
 | 
			
		||||
	 */
 | 
			
		||||
	private Boolean skipExecutingMigrations;
 | 
			
		||||
 | 
			
		||||
	public boolean isEnabled() {
 | 
			
		||||
		return this.enabled;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -678,4 +705,44 @@ public class FlywayProperties {
 | 
			
		|||
		this.undoSqlMigrationPrefix = undoSqlMigrationPrefix;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String[] getCherryPick() {
 | 
			
		||||
		return this.cherryPick;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setCherryPick(String[] cherryPick) {
 | 
			
		||||
		this.cherryPick = cherryPick;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public Map<String, String> getJdbcProperties() {
 | 
			
		||||
		return this.jdbcProperties;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setJdbcProperties(Map<String, String> jdbcProperties) {
 | 
			
		||||
		this.jdbcProperties = jdbcProperties;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getOracleKerberosCacheFile() {
 | 
			
		||||
		return this.oracleKerberosCacheFile;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setOracleKerberosCacheFile(String oracleKerberosCacheFile) {
 | 
			
		||||
		this.oracleKerberosCacheFile = oracleKerberosCacheFile;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getOracleKerberosConfigFile() {
 | 
			
		||||
		return this.oracleKerberosConfigFile;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setOracleKerberosConfigFile(String oracleKerberosConfigFile) {
 | 
			
		||||
		this.oracleKerberosConfigFile = oracleKerberosConfigFile;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public Boolean getSkipExecutingMigrations() {
 | 
			
		||||
		return this.skipExecutingMigrations;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setSkipExecutingMigrations(Boolean skipExecutingMigrations) {
 | 
			
		||||
		this.skipExecutingMigrations = skipExecutingMigrations;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -519,6 +519,61 @@ class FlywayAutoConfigurationTests {
 | 
			
		|||
				});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	void cherryPickIsCorrectlyMapped() {
 | 
			
		||||
		this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
 | 
			
		||||
				.withPropertyValues("spring.flyway.cherry-pick=1.1").run((context) -> {
 | 
			
		||||
					assertThat(context).hasFailed();
 | 
			
		||||
					Throwable failure = context.getStartupFailure();
 | 
			
		||||
					assertThat(failure).hasRootCauseInstanceOf(FlywayTeamsUpgradeRequiredException.class);
 | 
			
		||||
					assertThat(failure).hasMessageContaining(" migrations ");
 | 
			
		||||
				});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	void jdbcPropertiesAreCorrectlyMapped() {
 | 
			
		||||
		this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
 | 
			
		||||
				.withPropertyValues("spring.flyway.jdbc-properties.prop=value").run((context) -> {
 | 
			
		||||
					assertThat(context).hasFailed();
 | 
			
		||||
					Throwable failure = context.getStartupFailure();
 | 
			
		||||
					assertThat(failure).hasRootCauseInstanceOf(FlywayTeamsUpgradeRequiredException.class);
 | 
			
		||||
					assertThat(failure).hasMessageContaining(" jdbcProperties ");
 | 
			
		||||
				});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	void oracleKerberosCacheFileIsCorrectlyMapped() {
 | 
			
		||||
		this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
 | 
			
		||||
				.withPropertyValues("spring.flyway.oracle-kerberos-cache-file=/tmp/cache").run((context) -> {
 | 
			
		||||
					assertThat(context).hasFailed();
 | 
			
		||||
					Throwable failure = context.getStartupFailure();
 | 
			
		||||
					assertThat(failure).hasRootCauseInstanceOf(FlywayTeamsUpgradeRequiredException.class);
 | 
			
		||||
					assertThat(failure).hasMessageContaining(" oracle.kerberosCacheFile ");
 | 
			
		||||
				});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	void oracleKerberosConfigFileIsCorrectlyMapped() {
 | 
			
		||||
		this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
 | 
			
		||||
				.withPropertyValues("spring.flyway.oracle-kerberos-config-file=/tmp/config").run((context) -> {
 | 
			
		||||
					assertThat(context).hasFailed();
 | 
			
		||||
					Throwable failure = context.getStartupFailure();
 | 
			
		||||
					assertThat(failure).hasRootCauseInstanceOf(FlywayTeamsUpgradeRequiredException.class);
 | 
			
		||||
					assertThat(failure).hasMessageContaining(" oracle.kerberosConfigFile ");
 | 
			
		||||
				});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Test
 | 
			
		||||
	void skipExecutingMigrationsIsCorrectlyMapped() {
 | 
			
		||||
		this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
 | 
			
		||||
				.withPropertyValues("spring.flyway.skip-executing-migrations=true").run((context) -> {
 | 
			
		||||
					assertThat(context).hasFailed();
 | 
			
		||||
					Throwable failure = context.getStartupFailure();
 | 
			
		||||
					assertThat(failure).hasRootCauseInstanceOf(FlywayTeamsUpgradeRequiredException.class);
 | 
			
		||||
					assertThat(failure).hasMessageContaining(" skipExecutingMigrations ");
 | 
			
		||||
				});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Configuration(proxyBeanMethods = false)
 | 
			
		||||
	static class FlywayDataSourceConfiguration {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -115,9 +115,6 @@ class FlywayPropertiesTests {
 | 
			
		|||
		ignoreProperties(configuration, "shouldCreateSchemas");
 | 
			
		||||
		// Getters for the DataSource settings rather than actual properties
 | 
			
		||||
		ignoreProperties(configuration, "password", "url", "user");
 | 
			
		||||
		// Flyway 7.0 properties that are not yet supported
 | 
			
		||||
		ignoreProperties(configuration, "cherryPick", "jdbcProperties", "oracleKerberosCacheFile",
 | 
			
		||||
				"oracleKerberosConfigFile", "skipExecutingMigrations");
 | 
			
		||||
		List<String> configurationKeys = new ArrayList<>(configuration.keySet());
 | 
			
		||||
		Collections.sort(configurationKeys);
 | 
			
		||||
		List<String> propertiesKeys = new ArrayList<>(properties.keySet());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue