如何应对不断变化的 Flyway 迁移?
How to deal with changing Flyway migrations?
我目前正在调查 Flyway as an alternative to Liquibase,但无法在文档中找到以下问题的答案:
假设迁移 X
在生产部署后被发现包含错误。回想起来,X
不应该像 那样执行,但已经太晚了。但是,我们想用固定版本 X'
替换迁移 X
,这样从头开始填充的数据库就不会出现相同的错误。
在 Liquibase 中,您将修复原始变更集并使用 <validChecksum>
标记通知 Liquibase 更改是有意进行的。在 Flyway 中是否有 <validChecksum>
的挂件,或实现相同功能的替代机制?
根据乱七八糟的程度你也可以
- 只需进行后续迁移即可更正它(新列名称中的拼写错误,..)
- 如果这不是一个选项,您必须手动修复迁移和数据库并发出 Flyway.repair() 以重新对齐校验和 http://flywaydb.org/documentation/command/repair.html
如果已经投入生产,隐藏这个不良变化有什么意义?每次在空数据库上重播是否很昂贵(我假设 CI 运行)?使用已经包含的迁移创建新的数据库基线。
虽然这违反了 Flyway 的 API,但以下方法对我们来说效果很好:
写一个 beforeValidate.sql
修复校验和以匹配预期值,这样当 Flyway 实际验证校验和时,一切似乎都很好。
一个例子:
-- The script xyz/V03_201808230839__Faulty_migration.sql was modified to fix a critical bug.
-- However, at this point there were already production systems with the old migration file.
-- On these systems, no additional statements need to be executed to reflect the change,
-- BUT we need to repair the Flyway checksum to match the expected value during the 'validate' command.
UPDATE schema_version
SET checksum = -842223670
WHERE (version, checksum) = ('03.201808230839', -861395806);
这与 Flyway 的 repair
命令不同,它的优点是只针对一个特定的迁移。
我目前正在调查 Flyway as an alternative to Liquibase,但无法在文档中找到以下问题的答案:
假设迁移 X
在生产部署后被发现包含错误。回想起来,X
不应该像 那样执行,但已经太晚了。但是,我们想用固定版本 X'
替换迁移 X
,这样从头开始填充的数据库就不会出现相同的错误。
在 Liquibase 中,您将修复原始变更集并使用 <validChecksum>
标记通知 Liquibase 更改是有意进行的。在 Flyway 中是否有 <validChecksum>
的挂件,或实现相同功能的替代机制?
根据乱七八糟的程度你也可以
- 只需进行后续迁移即可更正它(新列名称中的拼写错误,..)
- 如果这不是一个选项,您必须手动修复迁移和数据库并发出 Flyway.repair() 以重新对齐校验和 http://flywaydb.org/documentation/command/repair.html
如果已经投入生产,隐藏这个不良变化有什么意义?每次在空数据库上重播是否很昂贵(我假设 CI 运行)?使用已经包含的迁移创建新的数据库基线。
虽然这违反了 Flyway 的 API,但以下方法对我们来说效果很好:
写一个 beforeValidate.sql
修复校验和以匹配预期值,这样当 Flyway 实际验证校验和时,一切似乎都很好。
一个例子:
-- The script xyz/V03_201808230839__Faulty_migration.sql was modified to fix a critical bug.
-- However, at this point there were already production systems with the old migration file.
-- On these systems, no additional statements need to be executed to reflect the change,
-- BUT we need to repair the Flyway checksum to match the expected value during the 'validate' command.
UPDATE schema_version
SET checksum = -842223670
WHERE (version, checksum) = ('03.201808230839', -861395806);
这与 Flyway 的 repair
命令不同,它的优点是只针对一个特定的迁移。