Polish "Auto-configure Flyway with JavaMigration beans"
See gh-17993
This commit is contained in:
@@ -123,8 +123,8 @@ public class FlywayAutoConfiguration {
|
||||
configureCallbacks(configuration, orderedCallbacks);
|
||||
fluentConfigurationCustomizers.orderedStream().forEach((customizer) -> customizer.customize(configuration));
|
||||
configureFlywayCallbacks(configuration, orderedCallbacks);
|
||||
JavaMigration[] migrations = javaMigrations.stream().toArray(JavaMigration[]::new);
|
||||
configuration.javaMigrations(migrations);
|
||||
List<JavaMigration> migrations = javaMigrations.stream().collect(Collectors.toList());
|
||||
configureJavaMigrations(configuration, migrations);
|
||||
return configuration.load();
|
||||
}
|
||||
|
||||
@@ -218,6 +218,12 @@ public class FlywayAutoConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
private void configureJavaMigrations(FluentConfiguration flyway, List<JavaMigration> migrations) {
|
||||
if (!migrations.isEmpty()) {
|
||||
flyway.javaMigrations(migrations.toArray(new JavaMigration[0]));
|
||||
}
|
||||
}
|
||||
|
||||
private String getProperty(Supplier<String> property, Supplier<String> defaultValue) {
|
||||
String value = property.get();
|
||||
return (value != null) ? value : defaultValue.get();
|
||||
|
||||
@@ -482,77 +482,17 @@ class FlywayAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
protected static class FlywayJavaMigrationsConfiguration {
|
||||
|
||||
@Component
|
||||
private static class Migration1 implements JavaMigration {
|
||||
|
||||
@Override
|
||||
public MigrationVersion getVersion() {
|
||||
return MigrationVersion.fromVersion("2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "M1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getChecksum() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUndo() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteInTransaction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate(org.flywaydb.core.api.migration.Context context) throws Exception {
|
||||
|
||||
}
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class FlywayJavaMigrationsConfiguration {
|
||||
|
||||
@Bean
|
||||
TestMigration migration1() {
|
||||
return new TestMigration("2", "M1");
|
||||
}
|
||||
|
||||
@Component
|
||||
private static class Migration2 implements JavaMigration {
|
||||
|
||||
@Override
|
||||
public MigrationVersion getVersion() {
|
||||
return MigrationVersion.fromVersion("3");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "M2";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getChecksum() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUndo() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteInTransaction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate(org.flywaydb.core.api.migration.Context context) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
TestMigration migration2() {
|
||||
return new TestMigration("3", "M2");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -669,4 +609,47 @@ class FlywayAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
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 isUndo() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteInTransaction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate(org.flywaydb.core.api.migration.Context context) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user