Support configuration of Flyway's Pro properties
Closes gh-14989
This commit is contained in:
parent
d3541fa672
commit
1eac4d6046
|
|
@ -221,6 +221,19 @@ public class FlywayAutoConfiguration {
|
|||
.to(configuration::skipDefaultResolvers);
|
||||
map.from(properties.isValidateOnMigrate())
|
||||
.to(configuration::validateOnMigrate);
|
||||
// Pro properties
|
||||
map.from(properties.getBatch()).whenNonNull().to(configuration::batch);
|
||||
map.from(properties.getDryRunOutput()).whenNonNull()
|
||||
.to(configuration::dryRunOutput);
|
||||
map.from(properties.getErrorOverrides()).whenNonNull()
|
||||
.to(configuration::errorOverrides);
|
||||
map.from(properties.getLicenseKey()).whenNonNull()
|
||||
.to(configuration::licenseKey);
|
||||
map.from(properties.getOracleSqlplus()).whenNonNull()
|
||||
.to(configuration::oracleSqlplus);
|
||||
map.from(properties.getStream()).whenNonNull().to(configuration::stream);
|
||||
map.from(properties.getUndoSqlMigrationPrefix()).whenNonNull()
|
||||
.to(configuration::undoSqlMigrationPrefix);
|
||||
}
|
||||
|
||||
private void configureCallbacks(FluentConfiguration configuration,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.flyway;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -224,6 +225,46 @@ public class FlywayProperties {
|
|||
*/
|
||||
private boolean validateOnMigrate = true;
|
||||
|
||||
/**
|
||||
* Whether to batch SQL statements when executing them. Requires Flyway Pro or Flyway
|
||||
* Enterprise.
|
||||
*/
|
||||
private Boolean batch = null;
|
||||
|
||||
/**
|
||||
* File to which the SQL statements of a migration dry run should be output. Requires
|
||||
* Flyway Pro or Flyway Enterprise.
|
||||
*/
|
||||
private File dryRunOutput = null;
|
||||
|
||||
/**
|
||||
* Rules for the built-in error handling to override specific SQL states and error
|
||||
* codes. Requires Flyway Pro or Flyway Enterprise.
|
||||
*/
|
||||
private String[] errorOverrides;
|
||||
|
||||
/**
|
||||
* Licence key for Flyway Pro or Flyway Enterprise.
|
||||
*/
|
||||
private String licenseKey;
|
||||
|
||||
/**
|
||||
* Whether to enable support for Oracle SQL*Plus commands. Requires Flyway Pro or
|
||||
* Flyway Enterprise.
|
||||
*/
|
||||
private Boolean oracleSqlplus = null;
|
||||
|
||||
/**
|
||||
* Whether to stream SQL migrarions when executing them. Requires Flyway Pro or Flyway
|
||||
* Enterprise.
|
||||
*/
|
||||
private Boolean stream = null;
|
||||
|
||||
/**
|
||||
* File name prefix for undo SQL migrations. Requires Flyway Pro or Flyway Enterprise.
|
||||
*/
|
||||
private String undoSqlMigrationPrefix = null;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
|
@ -516,4 +557,60 @@ public class FlywayProperties {
|
|||
this.validateOnMigrate = validateOnMigrate;
|
||||
}
|
||||
|
||||
public Boolean getBatch() {
|
||||
return this.batch;
|
||||
}
|
||||
|
||||
public void setBatch(Boolean batch) {
|
||||
this.batch = batch;
|
||||
}
|
||||
|
||||
public File getDryRunOutput() {
|
||||
return this.dryRunOutput;
|
||||
}
|
||||
|
||||
public void setDryRunOutput(File dryRunOutput) {
|
||||
this.dryRunOutput = dryRunOutput;
|
||||
}
|
||||
|
||||
public String[] getErrorOverrides() {
|
||||
return this.errorOverrides;
|
||||
}
|
||||
|
||||
public void setErrorOverrides(String[] errorOverrides) {
|
||||
this.errorOverrides = errorOverrides;
|
||||
}
|
||||
|
||||
public String getLicenseKey() {
|
||||
return this.licenseKey;
|
||||
}
|
||||
|
||||
public void setLicenseKey(String licenseKey) {
|
||||
this.licenseKey = licenseKey;
|
||||
}
|
||||
|
||||
public Boolean getOracleSqlplus() {
|
||||
return this.oracleSqlplus;
|
||||
}
|
||||
|
||||
public void setOracleSqlplus(Boolean oracleSqlplus) {
|
||||
this.oracleSqlplus = oracleSqlplus;
|
||||
}
|
||||
|
||||
public Boolean getStream() {
|
||||
return this.stream;
|
||||
}
|
||||
|
||||
public void setStream(Boolean stream) {
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
public String getUndoSqlMigrationPrefix() {
|
||||
return this.undoSqlMigrationPrefix;
|
||||
}
|
||||
|
||||
public void setUndoSqlMigrationPrefix(String undoSqlMigrationPrefix) {
|
||||
this.undoSqlMigrationPrefix = undoSqlMigrationPrefix;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import org.flywaydb.core.api.callback.Callback;
|
|||
import org.flywaydb.core.api.callback.Context;
|
||||
import org.flywaydb.core.api.callback.Event;
|
||||
import org.flywaydb.core.api.callback.FlywayCallback;
|
||||
import org.flywaydb.core.internal.license.FlywayProUpgradeRequiredException;
|
||||
import org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
|
@ -380,6 +381,95 @@ public class FlywayAutoConfigurationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void batchIsCorrectlyMapped() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.batch=true").run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
Throwable failure = context.getStartupFailure();
|
||||
assertThat(failure).hasRootCauseInstanceOf(
|
||||
FlywayProUpgradeRequiredException.class);
|
||||
assertThat(failure).hasMessageContaining(" batch ");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dryRunOutputIsCorrectlyMapped() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.dryRunOutput=dryrun.sql")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
Throwable failure = context.getStartupFailure();
|
||||
assertThat(failure).hasRootCauseInstanceOf(
|
||||
FlywayProUpgradeRequiredException.class);
|
||||
assertThat(failure).hasMessageContaining(" dryRunOutput ");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorOverridesIsCorrectlyMapped() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.errorOverrides=D12345")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
Throwable failure = context.getStartupFailure();
|
||||
assertThat(failure).hasRootCauseInstanceOf(
|
||||
FlywayProUpgradeRequiredException.class);
|
||||
assertThat(failure).hasMessageContaining(" errorOverrides ");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void licenseKeyIsCorrectlyMapped() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.license-key=<<secret>>")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
Throwable failure = context.getStartupFailure();
|
||||
assertThat(failure).hasRootCauseInstanceOf(
|
||||
FlywayProUpgradeRequiredException.class);
|
||||
assertThat(failure).hasMessageContaining(" licenseKey ");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oracleSqlplusIsCorrectlyMapped() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.oracle-sqlplus=true")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
Throwable failure = context.getStartupFailure();
|
||||
assertThat(failure).hasRootCauseInstanceOf(
|
||||
FlywayProUpgradeRequiredException.class);
|
||||
assertThat(failure).hasMessageContaining(" oracle.sqlplus ");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streamIsCorrectlyMapped() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.stream=true").run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
Throwable failure = context.getStartupFailure();
|
||||
assertThat(failure).hasRootCauseInstanceOf(
|
||||
FlywayProUpgradeRequiredException.class);
|
||||
assertThat(failure).hasMessageContaining(" stream ");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undoSqlMigrationPrefix() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.undo-sql-migration-prefix=undo")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
Throwable failure = context.getStartupFailure();
|
||||
assertThat(failure).hasRootCauseInstanceOf(
|
||||
FlywayProUpgradeRequiredException.class);
|
||||
assertThat(failure).hasMessageContaining(" undoSqlMigrationPrefix ");
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
protected static class FlywayDataSourceConfiguration {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -127,11 +127,10 @@ public class FlywayPropertiesTests {
|
|||
// Handled as initSql array
|
||||
ignoreProperties(configuration, "initSql");
|
||||
ignoreProperties(properties, "initSqls");
|
||||
// Pro version only
|
||||
ignoreProperties(configuration, "batch", "dryRunOutput", "dryRunOutputAsFile",
|
||||
"dryRunOutputAsFileName", "errorHandlers", "errorHandlersAsClassNames",
|
||||
"errorOverrides", "licenseKey", "oracleSqlplus", "stream",
|
||||
"undoSqlMigrationPrefix");
|
||||
// Handled as dryRunOutput
|
||||
ignoreProperties(configuration, "dryRunOutputAsFile", "dryRunOutputAsFileName");
|
||||
// Deprecated
|
||||
ignoreProperties(configuration, "errorHandlers", "errorHandlersAsClassNames");
|
||||
List<String> configurationKeys = new ArrayList<>(configuration.keySet());
|
||||
Collections.sort(configurationKeys);
|
||||
List<String> propertiesKeys = new ArrayList<>(properties.keySet());
|
||||
|
|
|
|||
Loading…
Reference in New Issue