阻止beforeMigrate运行最新模式

时间:2017-01-11 02:12:42

标签: flyway

当没有要运行的迁移时,是否可以阻止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();

根据日志,Flyway在确定架构是最新的并且没有要运行的迁移之前运行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 个答案:

答案 0 :(得分:3)

找到一个简单的解决方案;使用info确定是否存在挂起的迁移,并根据结果调用迁移条件: -

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

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