spring boot - How to run flyway:clean before migrations in a SpringBoot app? -


i using springboot , flyway. migrations work fine wanted able perform clean flyway command when application context gets loaded test profile.

is possible configure springboot clean , migrate if active profile test?

you can overwrite flyway autoconfiguration this:

@bean @profile("test") public flyway flyway(datasource thedatasource) {     flyway flyway = new flyway();     flyway.setdatasource(thedatasource);     flyway.setlocations("classpath:db/migration");     flyway.clean();     flyway.migrate();      return flyway; } 

in spring boot 1.3 (current version 1.3.0.m1, ga release planned september), can use flywaymigrationstrategy bean define actions want run:

@bean @profile("test") public flywaymigrationstrategy cleanmigratestrategy() {     flywaymigrationstrategy strategy = new flywaymigrationstrategy() {         @override         public void migrate(flyway flyway) {             flyway.clean();             flyway.migrate();         }     };      return strategy; } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -