可重复迁移的飞路和初始化

flyway and initialization of Repeatable migrations

https://flywaydb.org/documentation/migration/repeatable 引用 flyway 文档:

Repeatable migrations do not have a version. Instead they are (re-)applied every time their checksum changes.

This is very useful for managing database objects whose definition can then simply be maintained in a single file in version control.

Within a single migration run, repeatable migrations are always applied last, after all pending versioned migrations have been executed. Repeatable migrations are applied in the order of their description.

这听起来很令人兴奋,但我似乎找不到任何关于它实际如何工作以及如何初始化可重复迁移的说明。我知道对于版本化迁移,我可以创建一个基础迁移 (https://flywaydb.org/documentation/existing),然后 运行 基线命令为我的未来版本做好准备。但是,对于 可重复迁移,我不明白 flyway 如何能够更改校验和。

Instead they are

(re-)applied every time their checksum changes.

flyway 是否假设我正在从头开始重新创建我的数据库以使校验和比较工作?这将解释它如何能够比较校验和(因为它可以访问数据库中已有对象的文件定义)。

更新:我知道已经有一段时间了,我一直在寻找的解决方案是飞路修复。它会将预先存在的模式与 flyway 内部校验和 table 同步。 https://flywaydb.org/documentation/commandline/repair

我已经测试了 flyway,现在理解了初始化:flyway 将忽略现有的脚本/迁移,只要文件名没有特定前缀(我认为 'REPEATABLE' 是默认设置)- 只要由于未重命名要执行的迁移,flyway 将忽略它们。

让我们假设您的 repeatable 迁移 SQL 脚本的校验和是例如123.

  1. 第一次 运行 Flyway 它将检查 schema_version table,发现此 repeatable 迁移尚未应用,因此它将执行它。
  2. 第二次启动 Flyway 时,它将检查您的 SQL 脚本的校验和是否等于 123,这等于自上次以来 schema_version 中记录的内容,因此您的 repeatable 迁移脚本不会被执行。
  3. 现在假设您修改了第三个版本的 repeatable 迁移 SQL 脚本,并且校验和更改为例如987.当你启动Flyway时它会发现987不等于schema_version中仍然存储的(123)所以这次它会执行新版本的repeatable迁移SQL 然后将 schema_version 中的 123 校验和值更新为 987.

这意味着您可以根据需要继续使用每个新版本更改 repeatable 迁移脚本。您不能以这种方式更新基线(非重复table)脚本,因为 Flyway 会抛出有关校验和不匹配的错误。