What all the steps Liquibase follows while rolling back?

后端 未结 2 640
别跟我提以往
别跟我提以往 2021-01-26 07:17

I don\'t understand the detailed steps when rolling back using Liquibase.

I had scenario like 6 changesets and for one changeSet rollback was not defined - that is, on

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-26 08:00

    When running rollback, liquibase finds the changeSets to roll back, and then checks for a tag in each describing how to roll the changeSet back.

    If there is no tag, then Liquibase checks if the changes in the changeSet have built-in logic on how to roll themselves back. Like gile pointed out, if there is enough information in the change to undo it (like how the createTable change has the table name needed to drop the table) it will be able to still roll them back.

    But if there isn't enough information in the change (like how a dropTable doesn't have the information needed to re-create the table) then the rollback command will fail with a "cannot roll back" error.

    So the rollback logic is:

    1. Use what is defined in a block
    2. If no rollback block, try to deduce what is needed
    3. If there isn't enough information to roll back, exit before rolling back

    If you specify an empty rollback block, you are telling Liquibase "the logic needed to roll this back is to do nothing", so Liquibase happily runs your no-op rollback command and marks the changeSet as rolled back.

提交回复
热议问题