Does Liquibase support dry run?

后端 未结 4 902
梦毁少年i
梦毁少年i 2020-12-17 21:24

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

4条回答
  •  情话喂你
    2020-12-17 21:51

    I think your answer is "it does not support dry runs" but the problem is primarily with the database and not with liquibase.

    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 some databases that will rollback DDL SQL such as postgresql, but the majority do not.

    INSERT/UPDATE commands would run in a transaction and could be auto-rolled back at the end, but liquibase does not have a postCondition command to do the in-transaction check of the state that would be required. That would be a useful feature (https://liquibase.jira.com/browse/CORE-1793) but even it would not be usable if there are any auto-committing change tags in the changeset. If you added a postcondition to create table example above, the postcondition would fail and the update would fail, but the table would still be there.

提交回复
热议问题