Manually alter changesets
Some users find that liquibase update works well for incremental updates, but creating a database from scratch takes far too long. If you are creating and updating indexes frequently in your creation process, you may be able to combine those changesets into something more efficient.
Note: When you need to manually alter your existing changesets, remember how Liquibase works: each changeset has an id, an author, and a file path which together uniquely identifies it. If the DATABASECHANGELOG table has an entry for that changeset it will not run it. If it has an entry, it throws an error if the checksum for the changeset in the file doesn't match what was stored on the last run.
Modify, Merge, and Remove
Modify
How you modify your existing changesets will also depend on your environment and where in the changelog the problem changesets are. If you are modifying changesets that have been applied to all of your environments and are now only used on fresh database builds you can treat them differently than if they have been applied to some databases but not yet to others.
Merge
To merge or modify existing changesets you will be doing a combination of editing existing changesets, removing old changesets, and creating new ones.
Remove
Removing unneeded changesets is easy because Liquibase doesn't care about DATABASECHANGELOG rows with no corresponding changesets. Just delete out of date changesets and you are done. For example, if you have a changeset that creates the table cart and then another that drops it, just remove both changesets from the file. You must make sure, however, that there are no changesets between the create and the delete that make use of that table or they will fail on a fresh database build. That is an example of how you are introducing risk when changing your changelog file.
Combine everything into a new changeset using the existing id="1"
Suppose instead you have a cart
table that is created in one changeset, then a promo_code
column is created in another and an abandoned
flag is created in another. You can combine all of these items into one changeset with the id="1".
This will work well if all existing databases have the cart table with the promo_code
, and abandoned columns have already been added.
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
http://www.liquibase.org/xml/ns/pro
http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd">
<changeSet author="nvoxland" id="1">
<createTable tableName="cart">
<column name="id" type="int"/>
</createTable>
</changeSet>
<changeSet author="nvoxland" id="2">
<addColumn tableName="cart">
<column name="promo_code" type="varchar(10)"/>
</addColumn>
</changeSet>
<changeSet author="nvoxland" id="3">
<addColumn tableName="cart">
<column name="abandoned" type="boolean"/>
</addColumn>
</changeSet>
</databaseChangeLog>
To reduce the database creation time, delete the unnecessary changesets.