2015-06-14 85 views

回答

25

可以覆蓋遷飛自動配置是這樣的:

@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; 
} 

在春季啓動1.3(當前版本是1.3.0.M1,GA版本計劃於9月),你可以使用一個FlywayMigrationStrategy bean來定義你想要運行的動作:

@Bean 
@Profile("test") 
public FlywayMigrationStrategy cleanMigrateStrategy() { 
    FlywayMigrationStrategy strategy = new FlywayMigrationStrategy() { 
     @Override 
     public void migrate(Flyway flyway) { 
      flyway.clean(); 
      flyway.migrate(); 
     } 
    }; 

    return strategy; 
} 
+0

非常感謝@dunni,它有幫助! – Barbadoss

相關問題