Custom rollback

Using 1.9…

I have a rather intense changeSet that modifies tables and manipulates data.  If anything happens during that changeSet and I want to rollback, how can I be assured of the correct starting point for the rollback?

My idea was to use a customChange inside the rollback tag and handle it all inside java code, but then my question becomes - when are the rollback statements generated?  Are they only generated when a rollback occurs - or are they generated when the changeSet is executed?  If a changeSet in the future fails and I want to rollback multiple steps, will these rollback statements still be available for use?

Unfortunately you can’t.  Liquibase starts a transaction at the beginning of a changeSet, runs the changes, inserts into the databasechangelog, then commits the transaction.  If any changes fail, the transaction rolls back and on the next run it will re-start the changeSet from the beginning.

That works fine, except for when changes in the changeSet auto-commit. What statements auto-commit depend on your database, but generally any ddl (create/drop/alter) statements will autocommit.

Therefore, the best option is to have a single change per changeSet unless you know that the changes do not autocommit.

Nathan