liquibasechangeset

Combine multiple liquibase changeset to a single one


I am using liquibase to manage my DB and started the project with a single changeset where all the basic tables are created. Now my client wants to change that database and I am starting additional changesets, but I fear it will become a mess in a while (as in, not easy to read for the developers), as the first changeset is now not a real representation of the database schema.

Example :

<changeset id="1" author="natty">
  <createTable tableName="my_table">
    <column name="my_column" type="integer" />
  </createTable>
</changeset>
<changeset id="2" author="natty">
  <addColumn tableName="my_table">
    <column name="another_column" type="varchar(10)" />
  </addColumn>
</changeset>
[...]
<changeset id = "100" author="natty">
 ...
</changeset>

I now need full knowledge of all changesets to understand my database schema.

How can I avoid having multiple changeset ?


Solution

  • You are not supposed to alter your changesets. You're supposed to only add new changesets. Altering the changesets is an anti-pattern.

    Is you need to add changes to your database schema, you should keep the existing changesets and write new ones.

    If you don't want to make your changeLog file too massive, then create a parent changeLog file and some multiple child changeLog files (see include or includeAll tags). You can create a new child changeLog file like every month, or every week, or by some other logic.

    And if you really want to trim your changeLog, I suggest you read "Trimming Changelogs" article first.