gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 08:56:01 25 4
gpt4 key购买 nike

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 ),然后运行基线命令为我的 future 版本做好准备。但是,对于可重复迁移,我不明白 flyway 如何能够更改校验和。

Instead they are

(re-)applied every time their checksum changes.

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

最佳答案

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

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

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

关于database-migration - 可重复迁移的飞路和初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42930738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com