We have couple of data schemas and we investigate the migration to Liquibase. (One of data schemas is already migrated to Liquibase).
Important question for us is if Liquibase supports dry run:
- We need to run database changes on all schemas without commit to ensure we do not have problems. - In case of success all database changes run once again with commit.
Does Liquibase support control on transactions?
I want to open transaction before executing of Liquibase changelog, and to rollback the transaction after the changelog execution. Of course, I need to verify the result of the execution.
Your two options in liquibase are running in “update” mode where it actually executes the changesets or “updateSql” mode where it generates the SQL that would run which you can inspect and run as you want.
Liquibase does run each changeSet in a transaction and commits it after inserting into the DATABASECHANGELOG table so in theory you could override liquibase logic to roll back that transaction instead of committing it, but you will run into the problem where most SQL ran by liquibase is auto-committing.
For example, if you had a changeSet of:
What is ran is:
START TRANSACTION
CREATE TABLE NAME …
INSERT INTO DATABASECHANGELOG…
COMMIT
but even if you changed the last command to ROLLBACK the create table call will auto-commit when it runs and the only thing that will actually roll back is the INSERT.
NOTE: there are databases that will rollback DDL SQL but postgresql is the only one I know of.