迁移LiquibaseChangeLog条目 [英] Migrate LiquibaseChangeLog entries

查看:149
本文介绍了迁移LiquibaseChangeLog条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Liquibase来处理我们的数据库架构更改.由于我们已经有大量的ChangeLog分布在多个文件中,并以复杂的文件夹结构排列,因此有时会增加对某些重构的需求或渴望,这些重构会影响DatabaseChangeLog表中的元信息.

We're using Liquibase to handle our DB Schema changes. As we already have quite a large set of ChangeLogs distributed over multiple files, arranged in a complex folder structure, there sometimes rises the need or the desire to make some refactorings that would influence the meta information in the DatabaseChangeLog table.

对此类重构有何建议?我可以使用Liquibase本身来更新DatabaseChangeLog条目,还是会遇到缓存问题?

What is the recommendation for such refactorings? Can I use Liquibase itself to update the DatabaseChangeLog entries or will I run into caching issues?

一个使我的情况更清楚的简单示例:

A simple example to make my case clearer:

  • 我创建了一个新的changeLog文件test/changeLog.xml,其默认逻辑文件路径包含一些changeSets
  • 随着文件的变大,我想将其拆分为多个文件,在一些子文件夹中移动它们,并明确地将logicalFilePath属性设置为'myChanges'以便对它们进行分组
    • 因为这些更改已经在运行,所以我必须更新DATABASECHANGELOG.FILENAME字段,否则Liquibase会认为我已经引入了新的更改集
    • 我需要运行一个UPDATE DATABASECHANGELOG set FILENAME ='myChanges'WHERE FILENAME ='test/changelog.xml'
    • I have created a new changeLog file test/changeLog.xml with the default logicalFilePath containing a few changeSets
    • As the file grows bigger, I'd like to split it up into multiple files, move them around in some sub folders and explicitly set the logicalFilePath attribute to 'myChanges' to group them
      • As these changes have already run, I would have to update the DATABASECHANGELOG.FILENAME field, otherwise Liquibase will think that i have introduced new change sets
      • I would need to run an UPDATE DATABASECHANGELOG set FILENAME='myChanges' WHERE FILENAME='test/changelog.xml'

      感谢您的反馈!

      一些后续行动:

      有时候,不幸的是,变更集无法适应.考虑以下情况:

      Sometimes it's just unfortunate that change sets cannot be adapted. Consider the following case:

      • 我们用VARCHAR2(255字节)创建了一个新表
      • 一切都很好,表已部署并填充了数据
      • 我引入了一个嵌入式H2数据库进行测试,该数据库无法理解"255字节",但只能理解255.对于原始数据库,将其更改为VARCHAR(255)不会有什么不同,但会更改校验和变更集并导致Liquibase错误.
      • 删除和重新创建表也不是一种选择,因为该表已经填充了数据
      • 使用普通的Liquibase,我将得到一个解决方案,例如创建新表,移动数据,删除旧表并重命名新表...

      推荐答案

      Liquibase不支持重构变更日志文件.通常,它希望您在运行完之后就保持原样,以最大程度地减少意料之外的差异.

      There is no support in Liquibase for refactoring changelog files. It normally expects you to just leave things the way they are once they've been run to minimize unexpected differences.

      如果您想四处移动,则概述的步骤是您需要做的. LogicalFilePath会有所帮助,而更新databasechangelog.filename列应该是您需要做的全部事情.

      If you are wanting to move things around, the steps you outlined are what you would need to do. LogicalFilePath will help, and updating the databasechangelog.filename column should be all you need to do.

      重新组织文件后,您将需要在第一次运行liquibase之前更新文件名路径,否则它将再次执行changeSets. Liquibase在启动时会立即查看changelog表和changelog文件,因此您需要在Liquibase外部更新文件名列.

      You will need to update the filename path before you run liquibase the first time after reorganizing the files or it will execute the changeSets again. Liquibase looks at the changelog table and changelog file immediately on startup, so you will need to update the filename column outside of Liquibase.

      这篇关于迁移LiquibaseChangeLog条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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