Make FlywayMigrationStrategy an interface

Change FlywayMigrationStrategy from a class to an interface.

Fixes gh-3217
pull/3314/merge
Phillip Webb 10 years ago
parent 134bc02404
commit 4236a9336d

@ -75,6 +75,9 @@ public class FlywayAutoConfiguration {
@FlywayDataSource @FlywayDataSource
private DataSource flywayDataSource; private DataSource flywayDataSource;
@Autowired(required = false)
private FlywayMigrationStrategy migrationStrategy;
@PostConstruct @PostConstruct
public void checkLocationExists() { public void checkLocationExists() {
if (this.properties.isCheckLocation()) { if (this.properties.isCheckLocation()) {
@ -96,12 +99,6 @@ public class FlywayAutoConfiguration {
return false; return false;
} }
@Bean
@ConditionalOnMissingBean
public FlywayMigrationStrategy flywayMigrationStrategy() {
return new FlywayMigrationStrategy();
}
@Bean @Bean
@ConfigurationProperties(prefix = "flyway") @ConfigurationProperties(prefix = "flyway")
public Flyway flyway() { public Flyway flyway() {
@ -121,9 +118,8 @@ public class FlywayAutoConfiguration {
} }
@Bean @Bean
public FlywayMigrationInitializer flywayInitializer(Flyway flyway, public FlywayMigrationInitializer flywayInitializer(Flyway flyway) {
FlywayMigrationStrategy migrationStrategy) { return new FlywayMigrationInitializer(flyway, this.migrationStrategy);
return new FlywayMigrationInitializer(flyway, migrationStrategy);
} }
@ -163,7 +159,12 @@ public class FlywayAutoConfiguration {
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
this.migrationStrategy.migrate(this.flyway); if (this.migrationStrategy != null) {
this.migrationStrategy.migrate(this.flyway);
}
else {
this.flyway.migrate();
}
} }
} }

@ -25,10 +25,12 @@ import org.flywaydb.core.Flyway;
* @author Andreas Ahlenstorf * @author Andreas Ahlenstorf
* @author Phillip Webb * @author Phillip Webb
*/ */
public class FlywayMigrationStrategy { public interface FlywayMigrationStrategy {
public void migrate(Flyway flyway) { /**
flyway.migrate(); * Trigger flyway migration.
} * @param flyway the flyway instance
*/
void migrate(Flyway flyway);
} }

@ -180,7 +180,7 @@ public class FlywayAutoConfigurationTests {
} }
@Component @Component
protected static class MockFlywayMigrationStrategy extends FlywayMigrationStrategy { protected static class MockFlywayMigrationStrategy implements FlywayMigrationStrategy {
private boolean called = false; private boolean called = false;

Loading…
Cancel
Save