Remove support for Flyway 8.x and earlier
Closes gh-32036
This commit is contained in:
parent
5fdfc0d2b4
commit
c6872e57a9
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.boot.autoconfigure.flyway;
|
||||
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
@ -164,32 +165,25 @@ public class FlywayAutoConfiguration {
|
|||
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
||||
String[] locations = new LocationResolver(configuration.getDataSource())
|
||||
.resolveLocations(properties.getLocations()).toArray(new String[0]);
|
||||
configureFailOnMissingLocations(configuration, properties.isFailOnMissingLocations());
|
||||
map.from(properties.isFailOnMissingLocations()).to(configuration::failOnMissingLocations);
|
||||
map.from(locations).to(configuration::locations);
|
||||
map.from(properties.getEncoding()).to(configuration::encoding);
|
||||
map.from(properties.getConnectRetries()).to(configuration::connectRetries);
|
||||
// No method reference for compatibility with Flyway < 7.15
|
||||
map.from(properties.getConnectRetriesInterval())
|
||||
.to((interval) -> configuration.connectRetriesInterval((int) interval.getSeconds()));
|
||||
// No method reference for compatibility with Flyway 6.x
|
||||
map.from(properties.getLockRetryCount())
|
||||
.to((lockRetryCount) -> configuration.lockRetryCount(lockRetryCount));
|
||||
// No method reference for compatibility with Flyway 5.x
|
||||
map.from(properties.getDefaultSchema()).to((schema) -> configuration.defaultSchema(schema));
|
||||
map.from(properties.getConnectRetriesInterval()).as(Duration::getSeconds).as(Long::intValue)
|
||||
.to(configuration::connectRetriesInterval);
|
||||
map.from(properties.getLockRetryCount()).to(configuration::lockRetryCount);
|
||||
map.from(properties.getDefaultSchema()).to(configuration::defaultSchema);
|
||||
map.from(properties.getSchemas()).as(StringUtils::toStringArray).to(configuration::schemas);
|
||||
configureCreateSchemas(configuration, properties.isCreateSchemas());
|
||||
map.from(properties.isCreateSchemas()).to(configuration::createSchemas);
|
||||
map.from(properties.getTable()).to(configuration::table);
|
||||
// No method reference for compatibility with Flyway 5.x
|
||||
map.from(properties.getTablespace()).to((tablespace) -> configuration.tablespace(tablespace));
|
||||
map.from(properties.getTablespace()).to(configuration::tablespace);
|
||||
map.from(properties.getBaselineDescription()).to(configuration::baselineDescription);
|
||||
map.from(properties.getBaselineVersion()).to(configuration::baselineVersion);
|
||||
map.from(properties.getInstalledBy()).to(configuration::installedBy);
|
||||
map.from(properties.getPlaceholders()).to(configuration::placeholders);
|
||||
map.from(properties.getPlaceholderPrefix()).to(configuration::placeholderPrefix);
|
||||
map.from(properties.getPlaceholderSuffix()).to(configuration::placeholderSuffix);
|
||||
// No method reference for compatibility with Flyway version < 8.0
|
||||
map.from(properties.getPlaceholderSeparator())
|
||||
.to((placeHolderSeparator) -> configuration.placeholderSeparator(placeHolderSeparator));
|
||||
map.from(properties.getPlaceholderSeparator()).to(configuration::placeholderSeparator);
|
||||
map.from(properties.isPlaceholderReplacement()).to(configuration::placeholderReplacement);
|
||||
map.from(properties.getSqlMigrationPrefix()).to(configuration::sqlMigrationPrefix);
|
||||
map.from(properties.getSqlMigrationSuffixes()).as(StringUtils::toStringArray)
|
||||
|
@ -205,7 +199,7 @@ public class FlywayAutoConfiguration {
|
|||
map.from(properties.isOutOfOrder()).to(configuration::outOfOrder);
|
||||
map.from(properties.isSkipDefaultCallbacks()).to(configuration::skipDefaultCallbacks);
|
||||
map.from(properties.isSkipDefaultResolvers()).to(configuration::skipDefaultResolvers);
|
||||
configureValidateMigrationNaming(configuration, properties.isValidateMigrationNaming());
|
||||
map.from(properties.isValidateMigrationNaming()).to(configuration::validateMigrationNaming);
|
||||
map.from(properties.isValidateOnMigrate()).to(configuration::validateOnMigrate);
|
||||
map.from(properties.getInitSqls()).whenNot(CollectionUtils::isEmpty)
|
||||
.as((initSqls) -> StringUtils.collectionToDelimitedString(initSqls, "\n"))
|
||||
|
@ -214,63 +208,27 @@ public class FlywayAutoConfiguration {
|
|||
.to((prefix) -> configuration.scriptPlaceholderPrefix(prefix));
|
||||
map.from(properties.getScriptPlaceholderSuffix())
|
||||
.to((suffix) -> configuration.scriptPlaceholderSuffix(suffix));
|
||||
// Pro properties
|
||||
// Flyway Teams properties
|
||||
map.from(properties.getBatch()).to(configuration::batch);
|
||||
map.from(properties.getDryRunOutput()).to(configuration::dryRunOutput);
|
||||
map.from(properties.getErrorOverrides()).to(configuration::errorOverrides);
|
||||
map.from(properties.getLicenseKey()).to(configuration::licenseKey);
|
||||
map.from(properties.getOracleSqlplus()).to(configuration::oracleSqlplus);
|
||||
// No method reference for compatibility with Flyway 5.x
|
||||
map.from(properties.getOracleSqlplusWarn())
|
||||
.to((oracleSqlplusWarn) -> configuration.oracleSqlplusWarn(oracleSqlplusWarn));
|
||||
map.from(properties.getOracleSqlplusWarn()).to(configuration::oracleSqlplusWarn);
|
||||
map.from(properties.getStream()).to(configuration::stream);
|
||||
map.from(properties.getUndoSqlMigrationPrefix()).to(configuration::undoSqlMigrationPrefix);
|
||||
// No method reference for compatibility with Flyway 6.x
|
||||
map.from(properties.getCherryPick()).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.getKerberosConfigFile())
|
||||
.to((configFile) -> configuration.kerberosConfigFile(configFile));
|
||||
// No method reference for compatibility with Flyway 6.x
|
||||
map.from(properties.getOracleKerberosCacheFile())
|
||||
.to((cacheFile) -> configuration.oracleKerberosCacheFile(cacheFile));
|
||||
// No method reference for compatibility with Flyway 6.x
|
||||
map.from(properties.getOutputQueryResults())
|
||||
.to((outputQueryResults) -> configuration.outputQueryResults(outputQueryResults));
|
||||
map.from(properties.getCherryPick()).to(configuration::cherryPick);
|
||||
map.from(properties.getJdbcProperties()).whenNot(Map::isEmpty).to(configuration::jdbcProperties);
|
||||
map.from(properties.getKerberosConfigFile()).to(configuration::kerberosConfigFile);
|
||||
map.from(properties.getOracleKerberosCacheFile()).to(configuration::oracleKerberosCacheFile);
|
||||
map.from(properties.getOutputQueryResults()).to(configuration::outputQueryResults);
|
||||
map.from(properties.getSqlServerKerberosLoginFile()).whenNonNull()
|
||||
.to((sqlServerKerberosLoginFile) -> configureSqlServerKerberosLoginFile(configuration,
|
||||
sqlServerKerberosLoginFile));
|
||||
// No method reference for compatibility with Flyway 6.x
|
||||
map.from(properties.getSkipExecutingMigrations())
|
||||
.to((skipExecutingMigrations) -> configuration.skipExecutingMigrations(skipExecutingMigrations));
|
||||
// No method reference for compatibility with Flyway < 7.8
|
||||
map.from(properties.getSkipExecutingMigrations()).to(configuration::skipExecutingMigrations);
|
||||
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) {
|
||||
try {
|
||||
configuration.createSchemas(createSchemas);
|
||||
}
|
||||
catch (NoSuchMethodError ex) {
|
||||
// Flyway < 6.5
|
||||
}
|
||||
.as((patterns) -> patterns.toArray(new String[0])).to(configuration::ignoreMigrationPatterns);
|
||||
map.from(properties.getDetectEncoding()).to(configuration::detectEncoding);
|
||||
}
|
||||
|
||||
private void configureSqlServerKerberosLoginFile(FluentConfiguration configuration,
|
||||
|
@ -281,16 +239,6 @@ public class FlywayAutoConfiguration {
|
|||
sqlServerConfigurationExtension.setKerberosLoginFile(sqlServerKerberosLoginFile);
|
||||
}
|
||||
|
||||
private void configureValidateMigrationNaming(FluentConfiguration configuration,
|
||||
boolean validateMigrationNaming) {
|
||||
try {
|
||||
configuration.validateMigrationNaming(validateMigrationNaming);
|
||||
}
|
||||
catch (NoSuchMethodError ex) {
|
||||
// Flyway < 6.2
|
||||
}
|
||||
}
|
||||
|
||||
private void configureCallbacks(FluentConfiguration configuration, List<Callback> callbacks) {
|
||||
if (!callbacks.isEmpty()) {
|
||||
configuration.callbacks(callbacks.toArray(new Callback[0]));
|
||||
|
@ -305,12 +253,7 @@ public class FlywayAutoConfiguration {
|
|||
|
||||
private void configureJavaMigrations(FluentConfiguration flyway, List<JavaMigration> migrations) {
|
||||
if (!migrations.isEmpty()) {
|
||||
try {
|
||||
flyway.javaMigrations(migrations.toArray(new JavaMigration[0]));
|
||||
}
|
||||
catch (NoSuchMethodError ex) {
|
||||
// Flyway 5.x
|
||||
}
|
||||
flyway.javaMigrations(migrations.toArray(new JavaMigration[0]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,12 +73,12 @@ public class FlywayProperties {
|
|||
* duration suffix is not specified, seconds will be used.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration connectRetriesInterval;
|
||||
private Duration connectRetriesInterval = Duration.ofSeconds(120);
|
||||
|
||||
/**
|
||||
* Maximum number of retries when trying to obtain a lock.
|
||||
*/
|
||||
private Integer lockRetryCount;
|
||||
private int lockRetryCount = 50;
|
||||
|
||||
/**
|
||||
* Default schema name managed by Flyway (case-sensitive).
|
||||
|
@ -141,7 +141,7 @@ public class FlywayProperties {
|
|||
/**
|
||||
* Separator of default placeholders.
|
||||
*/
|
||||
private String placeholderSeparator;
|
||||
private String placeholderSeparator = ":";
|
||||
|
||||
/**
|
||||
* Perform placeholder replacement in migration scripts.
|
||||
|
@ -355,12 +355,12 @@ public class FlywayProperties {
|
|||
/**
|
||||
* Prefix of placeholders in migration scripts.
|
||||
*/
|
||||
private String scriptPlaceholderPrefix;
|
||||
private String scriptPlaceholderPrefix = "FP__";
|
||||
|
||||
/**
|
||||
* Suffix of placeholders in migration scripts.
|
||||
*/
|
||||
private String scriptPlaceholderSuffix;
|
||||
private String scriptPlaceholderSuffix = "__";
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
|
@ -410,7 +410,7 @@ public class FlywayProperties {
|
|||
this.connectRetriesInterval = connectRetriesInterval;
|
||||
}
|
||||
|
||||
public Integer getLockRetryCount() {
|
||||
public int getLockRetryCount() {
|
||||
return this.lockRetryCount;
|
||||
}
|
||||
|
||||
|
|
|
@ -1278,16 +1278,12 @@
|
|||
"level": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "spring.flyway.connect-retries-interval",
|
||||
"defaultValue": 120
|
||||
},
|
||||
{
|
||||
"name": "spring.flyway.dry-run-output",
|
||||
"type": "java.io.OutputStream",
|
||||
"deprecation": {
|
||||
"level": "error",
|
||||
"reason": "Flyway pro edition only."
|
||||
"reason": "Flyway Teams only."
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -1295,7 +1291,7 @@
|
|||
"type": "org.flywaydb.core.api.errorhandler.ErrorHandler[]",
|
||||
"deprecation": {
|
||||
"level": "error",
|
||||
"reason": "Flyway pro edition only."
|
||||
"reason": "Flyway Teams only."
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -1345,10 +1341,6 @@
|
|||
"classpath:db/migration"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "spring.flyway.lock-retry-count",
|
||||
"defaultValue": 50
|
||||
},
|
||||
{
|
||||
"name": "spring.flyway.oracle-kerberos-config-file",
|
||||
"type": "java.lang.String",
|
||||
|
@ -1357,18 +1349,6 @@
|
|||
"level": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "spring.flyway.placeholder-separator",
|
||||
"defaultValue": ":"
|
||||
},
|
||||
{
|
||||
"name": "spring.flyway.script-placeholder-prefix",
|
||||
"defaultValue": "FP__"
|
||||
},
|
||||
{
|
||||
"name": "spring.flyway.script-placeholder-suffix",
|
||||
"defaultValue": "__"
|
||||
},
|
||||
{
|
||||
"name": "spring.flyway.sql-migration-suffix",
|
||||
"type": "java.lang.String",
|
||||
|
@ -1389,7 +1369,7 @@
|
|||
"type": "java.lang.String",
|
||||
"deprecation": {
|
||||
"level": "error",
|
||||
"reason": "Flyway pro edition only."
|
||||
"reason": "Flyway Teams only."
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -1,118 +0,0 @@
|
|||
/*
|
||||
* Copyright 2012-2022 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.flyway;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.flywaydb.core.Flyway;
|
||||
import org.flywaydb.core.api.Location;
|
||||
import org.flywaydb.core.api.MigrationVersion;
|
||||
import org.flywaydb.core.api.migration.JavaMigration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link FlywayAutoConfiguration} with Flyway 5.x.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@ClassPathOverrides("org.flywaydb:flyway-core:5.2.4")
|
||||
class Flyway5xAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class))
|
||||
.withPropertyValues("spring.datasource.url:jdbc:hsqldb:mem:" + UUID.randomUUID());
|
||||
|
||||
@Test
|
||||
void defaultFlyway() {
|
||||
this.contextRunner.withUserConfiguration(DataSourceAutoConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(Flyway.class);
|
||||
Flyway flyway = context.getBean(Flyway.class);
|
||||
assertThat(flyway.getConfiguration().getLocations())
|
||||
.containsExactly(new Location("classpath:db/migration"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void flywayJavaMigrationsAreIgnored() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(DataSourceAutoConfiguration.class, FlywayJavaMigrationsConfiguration.class)
|
||||
.run((context) -> assertThat(context).hasNotFailed());
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class FlywayJavaMigrationsConfiguration {
|
||||
|
||||
@Bean
|
||||
TestMigration migration1() {
|
||||
return new TestMigration("2", "M1");
|
||||
}
|
||||
|
||||
@Bean
|
||||
TestMigration migration2() {
|
||||
return new TestMigration("3", "M2");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class TestMigration implements JavaMigration {
|
||||
|
||||
private final MigrationVersion version;
|
||||
|
||||
private final String description;
|
||||
|
||||
private TestMigration(String version, String description) {
|
||||
this.version = MigrationVersion.fromVersion(version);
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MigrationVersion getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getChecksum() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteInTransaction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate(org.flywaydb.core.api.migration.Context context) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
* Copyright 2012-2022 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.flyway;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.flywaydb.core.Flyway;
|
||||
import org.flywaydb.core.api.Location;
|
||||
import org.flywaydb.core.api.callback.Callback;
|
||||
import org.flywaydb.core.api.callback.Context;
|
||||
import org.flywaydb.core.api.callback.Event;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link FlywayAutoConfiguration} with Flyway 6.x.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@ClassPathOverrides("org.flywaydb:flyway-core:6.5.6")
|
||||
class Flyway6xAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class))
|
||||
.withPropertyValues("spring.datasource.url:jdbc:hsqldb:mem:" + UUID.randomUUID());
|
||||
|
||||
@Test
|
||||
void defaultFlyway() {
|
||||
this.contextRunner.withUserConfiguration(DataSourceAutoConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(Flyway.class);
|
||||
Flyway flyway = context.getBean(Flyway.class);
|
||||
assertThat(flyway.getConfiguration().getLocations())
|
||||
.containsExactly(new Location("classpath:db/migration"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void callbacksAreConfiguredAndOrdered() {
|
||||
this.contextRunner.withUserConfiguration(DataSourceAutoConfiguration.class, CallbackConfiguration.class)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(Flyway.class);
|
||||
Flyway flyway = context.getBean(Flyway.class);
|
||||
Callback callbackOne = context.getBean("callbackOne", Callback.class);
|
||||
Callback callbackTwo = context.getBean("callbackTwo", Callback.class);
|
||||
assertThat(flyway.getConfiguration().getCallbacks()).hasSize(2);
|
||||
assertThat(flyway.getConfiguration().getCallbacks()).containsExactly(callbackTwo, callbackOne);
|
||||
InOrder orderedCallbacks = inOrder(callbackOne, callbackTwo);
|
||||
orderedCallbacks.verify(callbackTwo).handle(any(Event.class), any(Context.class));
|
||||
orderedCallbacks.verify(callbackOne).handle(any(Event.class), any(Context.class));
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class CallbackConfiguration {
|
||||
|
||||
@Bean
|
||||
@Order(1)
|
||||
Callback callbackOne() {
|
||||
return mockCallback();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Order(0)
|
||||
Callback callbackTwo() {
|
||||
return mockCallback();
|
||||
}
|
||||
|
||||
private Callback mockCallback() {
|
||||
Callback callback = mock(Callback.class);
|
||||
given(callback.supports(any(Event.class), any(Context.class))).willReturn(true);
|
||||
return callback;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* Copyright 2012-2022 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.flyway;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.flywaydb.core.Flyway;
|
||||
import org.flywaydb.core.api.Location;
|
||||
import org.flywaydb.core.api.callback.Callback;
|
||||
import org.flywaydb.core.api.callback.Context;
|
||||
import org.flywaydb.core.api.callback.Event;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link FlywayAutoConfiguration} with Flyway 7.x.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@ClassPathOverrides("org.flywaydb:flyway-core:7.15.0")
|
||||
class Flyway7xAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class))
|
||||
.withPropertyValues("spring.datasource.url:jdbc:hsqldb:mem:" + UUID.randomUUID());
|
||||
|
||||
@Test
|
||||
void defaultFlyway() {
|
||||
this.contextRunner.withUserConfiguration(DataSourceAutoConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(Flyway.class);
|
||||
Flyway flyway = context.getBean(Flyway.class);
|
||||
assertThat(flyway.getConfiguration().getLocations())
|
||||
.containsExactly(new Location("classpath:db/migration"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void callbacksAreConfigured() {
|
||||
this.contextRunner.withUserConfiguration(DataSourceAutoConfiguration.class, CallbackConfiguration.class)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(Flyway.class);
|
||||
Flyway flyway = context.getBean(Flyway.class);
|
||||
Callback callbackOne = context.getBean("callbackOne", Callback.class);
|
||||
Callback callbackTwo = context.getBean("callbackTwo", Callback.class);
|
||||
assertThat(flyway.getConfiguration().getCallbacks()).hasSize(2);
|
||||
assertThat(flyway.getConfiguration().getCallbacks()).containsExactlyInAnyOrder(callbackTwo,
|
||||
callbackOne);
|
||||
then(callbackOne).should(atLeastOnce()).handle(any(Event.class), any(Context.class));
|
||||
then(callbackTwo).should(atLeastOnce()).handle(any(Event.class), any(Context.class));
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class CallbackConfiguration {
|
||||
|
||||
@Bean
|
||||
Callback callbackOne() {
|
||||
return mockCallback();
|
||||
}
|
||||
|
||||
@Bean
|
||||
Callback callbackTwo() {
|
||||
return mockCallback();
|
||||
}
|
||||
|
||||
private Callback mockCallback() {
|
||||
Callback callback = mock(Callback.class);
|
||||
given(callback.supports(any(Event.class), any(Context.class))).willReturn(true);
|
||||
given(callback.getCallbackName()).willReturn("callback");
|
||||
return callback;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.boot.autoconfigure.flyway;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -48,17 +49,14 @@ class FlywayPropertiesTests {
|
|||
void defaultValuesAreConsistent() {
|
||||
FlywayProperties properties = new FlywayProperties();
|
||||
Configuration configuration = new FluentConfiguration();
|
||||
assertThat(configuration.isFailOnMissingLocations()).isEqualTo(properties.isFailOnMissingLocations());
|
||||
assertThat(properties.isFailOnMissingLocations()).isEqualTo(configuration.isFailOnMissingLocations());
|
||||
assertThat(properties.getLocations().stream().map(Location::new).toArray(Location[]::new))
|
||||
.isEqualTo(configuration.getLocations());
|
||||
assertThat(properties.getEncoding()).isEqualTo(configuration.getEncoding());
|
||||
assertThat(properties.getConnectRetries()).isEqualTo(configuration.getConnectRetries());
|
||||
// Can't assert connect retries interval as it is new in Flyway 7.15
|
||||
// Asserting hard-coded value in the metadata instead
|
||||
assertThat(configuration.getConnectRetriesInterval()).isEqualTo(120);
|
||||
// Can't assert lock retry count default as it is new in Flyway 7.1
|
||||
// Asserting hard-coded value in the metadata instead
|
||||
assertThat(configuration.getLockRetryCount()).isEqualTo(50);
|
||||
assertThat(properties.getConnectRetriesInterval()).extracting(Duration::getSeconds).extracting(Long::intValue)
|
||||
.isEqualTo(configuration.getConnectRetriesInterval());
|
||||
assertThat(properties.getLockRetryCount()).isEqualTo(configuration.getLockRetryCount());
|
||||
assertThat(properties.getDefaultSchema()).isEqualTo(configuration.getDefaultSchema());
|
||||
assertThat(properties.getSchemas()).isEqualTo(Arrays.asList(configuration.getSchemas()));
|
||||
assertThat(properties.isCreateSchemas()).isEqualTo(configuration.isCreateSchemas());
|
||||
|
@ -72,28 +70,27 @@ class FlywayPropertiesTests {
|
|||
assertThat(properties.getPlaceholderSuffix()).isEqualTo(configuration.getPlaceholderSuffix());
|
||||
assertThat(properties.isPlaceholderReplacement()).isEqualTo(configuration.isPlaceholderReplacement());
|
||||
assertThat(properties.getSqlMigrationPrefix()).isEqualTo(configuration.getSqlMigrationPrefix());
|
||||
assertThat(properties.getSqlMigrationSuffixes())
|
||||
.isEqualTo(Arrays.asList(configuration.getSqlMigrationSuffixes()));
|
||||
assertThat(properties.getSqlMigrationSeparator()).isEqualTo(properties.getSqlMigrationSeparator());
|
||||
assertThat(properties.getSqlMigrationSuffixes()).containsExactly(configuration.getSqlMigrationSuffixes());
|
||||
assertThat(properties.getSqlMigrationSeparator()).isEqualTo(configuration.getSqlMigrationSeparator());
|
||||
assertThat(properties.getRepeatableSqlMigrationPrefix())
|
||||
.isEqualTo(properties.getRepeatableSqlMigrationPrefix());
|
||||
assertThat(properties.getTarget()).isNull();
|
||||
assertThat(configuration.getTarget()).isNull();
|
||||
.isEqualTo(configuration.getRepeatableSqlMigrationPrefix());
|
||||
assertThat(properties.getTarget()).isEqualTo(configuration.getTarget());
|
||||
assertThat(configuration.getInitSql()).isNull();
|
||||
assertThat(properties.getInitSqls()).isEmpty();
|
||||
assertThat(configuration.isBaselineOnMigrate()).isEqualTo(properties.isBaselineOnMigrate());
|
||||
assertThat(configuration.isCleanDisabled()).isEqualTo(properties.isCleanDisabled());
|
||||
assertThat(configuration.isCleanOnValidationError()).isEqualTo(properties.isCleanOnValidationError());
|
||||
assertThat(configuration.isGroup()).isEqualTo(properties.isGroup());
|
||||
assertThat(configuration.isMixed()).isEqualTo(properties.isMixed());
|
||||
assertThat(configuration.isOutOfOrder()).isEqualTo(properties.isOutOfOrder());
|
||||
assertThat(configuration.isSkipDefaultCallbacks()).isEqualTo(properties.isSkipDefaultCallbacks());
|
||||
assertThat(configuration.isSkipDefaultResolvers()).isEqualTo(properties.isSkipDefaultResolvers());
|
||||
assertThat(configuration.isValidateMigrationNaming()).isEqualTo(properties.isValidateMigrationNaming());
|
||||
assertThat(configuration.isValidateOnMigrate()).isEqualTo(properties.isValidateOnMigrate());
|
||||
assertThat(properties.isBaselineOnMigrate()).isEqualTo(configuration.isBaselineOnMigrate());
|
||||
assertThat(properties.isCleanDisabled()).isEqualTo(configuration.isCleanDisabled());
|
||||
assertThat(properties.isCleanOnValidationError()).isEqualTo(configuration.isCleanOnValidationError());
|
||||
assertThat(properties.isGroup()).isEqualTo(configuration.isGroup());
|
||||
assertThat(properties.isMixed()).isEqualTo(configuration.isMixed());
|
||||
assertThat(properties.isOutOfOrder()).isEqualTo(configuration.isOutOfOrder());
|
||||
assertThat(properties.isSkipDefaultCallbacks()).isEqualTo(configuration.isSkipDefaultCallbacks());
|
||||
assertThat(properties.isSkipDefaultResolvers()).isEqualTo(configuration.isSkipDefaultResolvers());
|
||||
assertThat(properties.isValidateMigrationNaming()).isEqualTo(configuration.isValidateMigrationNaming());
|
||||
assertThat(properties.isValidateOnMigrate()).isEqualTo(configuration.isValidateOnMigrate());
|
||||
assertThat(properties.getDetectEncoding()).isNull();
|
||||
assertThat(configuration.getScriptPlaceholderPrefix()).isEqualTo("FP__");
|
||||
assertThat(configuration.getScriptPlaceholderSuffix()).isEqualTo("__");
|
||||
assertThat(properties.getPlaceholderSeparator()).isEqualTo(configuration.getPlaceholderSeparator());
|
||||
assertThat(properties.getScriptPlaceholderPrefix()).isEqualTo(configuration.getScriptPlaceholderPrefix());
|
||||
assertThat(properties.getScriptPlaceholderSuffix()).isEqualTo(configuration.getScriptPlaceholderSuffix());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue