Flyway 防止beforeMigrate在最新架构上运行

Flyway 防止beforeMigrate在最新架构上运行,flyway,Flyway,由于架构已经是最新的,因此没有要运行的迁移时,是否可以阻止beforeMigrate回调脚本运行 以下是代码(在应用程序启动时执行):- 根据日志,Flyway在确定架构是最新的并且没有要运行的迁移之前运行beforeMigrate回调 INFO: Flyway 4.0.3 by Boxfuse INFO: Database: jdbc:oracle:thin:... (Oracle 11.2) INFO: Successfully validated 8 migrations (executi

由于架构已经是最新的,因此没有要运行的迁移时,是否可以阻止beforeMigrate回调脚本运行

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

根据日志,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回调仅在需要迁移时运行。

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

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

if (pending) {
    flyway.migrate();
}
boolean pending = flyway.info().pending().length > 0;

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