Migrate LiquibaseChangeLog Records

We use Liquibase to process our database schema changes. Since we already have a fairly large set of ChangeLogs distributed across several files located in a complex folder structure, sometimes there is a need or desire to make some refactoring that affects the meta-information in the DatabaseChangeLog table.

What is the recommendation for such refactoring? Can I use Liquibase myself to update DatabaseChangeLog entries or will I encounter caching issues?

A simple example to make my drawer clearer:

  • I created a new changeLog file test / changeLog.xml with a default logicalFilePath containing several changeSets
  • As the file size grows, I would like to split it into several files, move them to some subfolders, and explicitly set the logicalFilePath attribute to "myChanges" to group them
    • Since these changes have already been made, I will have to update the DATABASECHANGELOG.FILENAME field, otherwise Liquibase will think that I have introduced new change shifts.
    • I need to run the UPDATE DATABASECHANGELOG set FILENAME = 'myChanges' WHERE FILENAME = 'test / changelog.xml'
  • Of course I want to do this in an automatic way. What is the best way to do this? Can I use Liquibase? Or do I need to update DATABASECHANGELOG differently (JDBC or something else) before I run Liquibase with a new structure?

Thanks for the feedback!

Some follow-up actions:

It is sometimes regrettable that change sets cannot be adapted. Consider the following case:

  • We created a new table with VARCHAR2 (255 bytes)
  • Everything was fine, the table was expanded and filled with data
  • I presented a built-in H2 test database that does not understand β€œ255 bytes”, but only 255. For the original database, changing it to VARCHAR (255) would not change, but it would change the checksum of the change set and result in a Liquibase error.
  • Dropping and re-creating the table is not an option since the table is already filled with data
  • Using simple Liquibase, I get a solution like creating a new table, moving my data, deleting the old table and renaming the new ...
0
liquibase
source share
1 answer

Liquibase has no support for refactoring change files. Usually he expects you to just leave things as soon as they are launched in order to minimize unexpected differences.

If you want to move things, the steps you described are what you will 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 path to the file name before starting linibase for the first time after the files are reorganized or it will run changeSets again. Liquibase looks at the change table and change file immediately at startup, so you will need to update the file name column outside of Liquibase.

+1
source share

All Articles