最佳实践:使用Flyway迁移脚本后如何对其进行修改 [英] Best practice: How to modify flyway migration script after it has been used

查看:549
本文介绍了最佳实践:使用Flyway迁移脚本后如何对其进行修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下情况下,我正在寻求建议.

I am looking for an advice in the following case.

我在生产环境中设置了flyway迁移脚本.在每次部署中,数据库都将迁移到当前版本. 我已经创建了一些迁移脚本,这些脚本已应用于生产数据库.

I set up flyway migration scripts in my production environment. On every deployment the database will be migrated to the current version. I already have created several migrations scripts which have been applied to the production database.

最近,我升级了我的开发MySQL工具,该工具现在包括有关不赞成使用的功能的警告和其他警告.这些警告未在较旧的版本中显示. 当然,我想修复警告,特别是在数据库的将来版本不再支持不推荐使用的功能的情况下. 但是包含警告的迁移已被部署和使用.如果我更改其中一个脚本,则会出现飞行警告:

Recently I upgraded my development MySQL tools which now include warnings about usage of deprecated functions and other warnings. These warnings have not been displayed in the older version. Of course I would like to fix the warnings, especially for the case when a future version of the database does not support the deprecated functions any more. But the migrations containing the warnings have already been deployed and used. If I change one of the scripts there is a flyway warning:

ERROR: Validate failed. Migration Checksum mismatch for migration 2.0
-> Applied to database : 1778293504
-> Resolved locally    : 1831545539

我可以更改存储在数据库中的校验和以进行迁移,但这听起来不像是好".做到的方式. 在已使用迁移脚本 之后更改迁移脚本的常用方法/最佳做法是什么?

I could change the checksum which is stored in the database to migrate, but that does not sound like a "good" way to do it. What is the common way / best practice to change a migration script after it has already been used?

推荐答案

第一个规则不是.

第二个方法非常小心,并使用Flyway.repair()将数据库中的校验和与磁盘上的校验和重新对齐.

The second one is do it very carefully and use Flyway.repair() to realign the checksums in the DB with the ones on disk.

这篇关于最佳实践:使用Flyway迁移脚本后如何对其进行修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆