可以“压缩"任何方式.飞路迁移? [英] Any way to "compress" Flyway migrations?

查看:64
本文介绍了可以“压缩"任何方式.飞路迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Flyway迁移数据库架构,我们已经有100多个迁移脚本.

We are using Flyway to migrate the database schema and we already have more than 100 migration scripts.

一旦我们将多个迁移压缩"到一个第一版迁移中,那么在开发过程中就可以了,因为我们删除并重新创建了架构.但是在生产中这是行不通的,因为Flyway无法验证迁移.

Once we "squashed" multiple migrations into a single first-version migration, this is ok during development, as we drop and recreate the schema. But in production this wouldn't work, as Flyway won't be able to validate the migrations.

在这种情况下,我找不到任何文档或最佳实践.问题在于文件数量不断增加,我不想每次都看到成千上万个迁移文件,本质上是如果生产已经是最新版本.我的意思是,版本号低于生产版本的迁移脚本与我们无关,如果我们可以将这些文件压缩到单个迁移中,那就太好了.

I couldn't find any documentation or best practice of what to do in this case. The problem is that the file quantity increases constantly, I don't want to see thousands of migration files everytime, essentially if production is already in the latest version. I mean, the migration scripts that have a version number that is lower than the version in production are irrelevant to us, it would be awesome if we could squash those files into a single migration.

我们正在使用MySQL.

We are using MySQL.

我们应该如何处理呢?

推荐答案

不是重新基准化会做什么?

Isn't that what re-baselining would do?

我仍然是新手,但是我认为这是可行的.请先测试以下内容,然后再说我的话.

I'm still new to flyway, but this is how I think it would work. Please test the following first before taking my word for it.

删除schema_version表. 删除您的迁移脚本.

Delete the schema_version table. Delete your migration scripts.

运行飞行基线 (这将重新创建schema_version表并添加基线记录作为版本1)

Run flyway baseline (this recreates the schema_version table and adds a baseline record as version 1)

现在你很好.请记住,由于删除了所有迁移脚本,因此您将无法迁移"到任何以前的版本,但这对您来说可能不是问题.

Now you're good to go. Bear in mind that you will not be able to 'migrate' to any prior version as you've removed all of your migration scripts, but this might not be a problem for you.

分步解决方案:

  1. drop table schema_version;
  2. 例如,通过MySQL Workbench将数据库结构导出为脚本.将此脚本命名为V1__Baseline.sql
  3. 删除所有迁移脚本并将V1__Baseline.sql添加到您的脚本文件夹中,因此它是Flyway唯一可用的脚本
  4. 运行Flyway的基线"命令
  5. 完成
  1. drop table schema_version;
  2. Export database structure as a script via MySQL Workbench, for example. Name this script V1__Baseline.sql
  3. Delete all migration scripts and add V1__Baseline.sql to your scripts folder, so it is the only script available for Flyway
  4. Run Flyway's "baseline" command
  5. Done

这篇关于可以“压缩"任何方式.飞路迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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