2017-01-11 167 views
1

当没有要迁移的迁移时可以防止beforeMigrate回调脚本运行,因为该模式已经是最新的吗?在迁移之前防止迁移到最新模式

下面的代码(在应用程序启动时执行): -

Flyway flyway = new Flyway(); 

flyway.setDataSource(url, user, password); 

flyway.setLocations(scriptsLocations); 
flyway.setPlaceholders(placeHolders); 

flyway.setBaselineVersionAsString("7.0"); 
flyway.setBaselineOnMigrate(true); 

flyway.migrate(); 

根据日志迁徙路线运行beforeMigrate回调决定架构之前是最新的,并且没有迁移到运行。

INFO: Flyway 4.0.3 by Boxfuse 
INFO: Database: jdbc:oracle:thin:... (Oracle 11.2) 
INFO: Successfully validated 8 migrations (execution time 00:00.023s) 
INFO: Executing SQL callback: beforeMigrate 
INFO: Current version of schema "...": 7.0.7 
INFO: Schema "..." is up to date. No migration necessary. 

想要beforeMigrate回调仅在需要迁移时运行。

回答

1

找到了一个简单的解决方案;使用info来确定是否存在未决迁移并根据结果进行有条件迁移的调用: -

boolean pending = flyway.info().pending().length > 0; 

if (pending) { 
    flyway.migrate(); 
}