Skip to content

Instantly share code, notes, and snippets.

@hikoma
Created March 17, 2015 09:44
Show Gist options
  • Save hikoma/c4a339d0b7c893f5450b to your computer and use it in GitHub Desktop.
Save hikoma/c4a339d0b7c893f5450b to your computer and use it in GitHub Desktop.
Force clean detabase before flyway migration
import org.flywaydb.core.Flyway;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Flyway database cleanup.
*/
@Configuration
@ConditionalOnClass(Flyway.class)
@ConditionalOnBean(DataSource.class)
@ConditionalOnProperty(prefix = "flyway", name = "enabled", matchIfMissing = true)
@AutoConfigureBefore(FlywayAutoConfiguration.class)
public class FlywayCleanAutoConfiguration {
@Configuration
public static class FlywayCleanConfiguration extends FlywayAutoConfiguration.FlywayConfiguration {
@Bean(name = "flywayClean", initMethod = "clean")
@Override
public Flyway flyway() {
return super.flyway();
}
}
}
@hikoma
Copy link
Author

hikoma commented Mar 17, 2015

Use flyway.cleanOnValidationError=true instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment