Migrate LiquibaseChangeLog entries

99封情书 提交于 2019-12-12 04:53:59

问题


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.

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:

  • 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'
  • Of course, I want to do this in an automated way. What's the best way to do it? Can I use Liquibase itself? Or do I need to update DATABASECHANGELOG in another way (JDBC or whatever) BEFORE I run Liquibase with the new structure?

Thanks for a feedback!

Some follow up:

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

  • We created a new table with VARCHAR2(255 byte)
  • Everything was fine, table was deployed and populated with data
  • I introduced an embedded H2 database for testing that wouldn't understand "255 byte", but only 255. For the original database, changing it to VARCHAR(255) wouldn't make a difference, but it would change the checksum of the changeset and lead to a Liquibase error.
  • Dropping and recreating the table isn't an option either as the table is already populated with data
  • Using plain Liquibase, I would end up with a solution like creating a new table, moving over my data, deleting the old table and renaming the new one...

回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/25841202/migrate-liquibasechangelog-entries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!