回滚时,Liquibase遵循的所有步骤是什么? [英] What all the steps Liquibase follows while rolling back?

查看:475
本文介绍了回滚时,Liquibase遵循的所有步骤是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不了解使用Liquibase回滚时的详细步骤.

我有类似6个变更集的情况,并且其中一个changeSet回滚未定义-也就是说,变更集内只有<rollback/>.

使用deployIT执行后,我可以在Databasechangelog表中看到7个条目,其中6个用于添加,一个用于由于使用deployIT而创建标签.

回滚后,我看到删除所有新添加的6个变更集的行为,即使六个变更集之一具有空的回滚标记.

请任何专家告诉我为什么?回滚的确切行为是什么?

总体想知道何时从Databasechangelog中删除记录?

解决方案

运行回滚时,liquibase找到要回滚的changeSet,然后在每个描述如何回滚changeSet的<rollback>标记中进行检查. >

如果没有<rollback>标记,则Liquibase将检查changeSet中的更改是否具有有关如何回滚自身的内置逻辑.就像gile指出的那样,如果更改中有足够的信息来撤消它(例如createTable更改如何具有删除该表所需的表名),则仍可以将它们回滚.

但是,如果更改中没有足够的信息(例如dropTable如何没有重新创建表所需的信息),则rollback命令将失败,并显示无法回滚"错误.

所以回滚逻辑是:

  1. 使用块中定义的内容
  2. 如果没有回滚阻止,请尝试推断出所需的条件
  3. 如果没有足够的信息可以回滚,请在回滚之前退出

如果您指定一个空的回滚块,您将告诉Liquibase回滚所需的逻辑是什么都不做",因此Liquibase会愉快地运行您的no-op rollback命令,并将changeSet标记为已回滚.

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, only <rollback/> within the changeset.

After executing using deployIT I could see 7 entries in Databasechangelog table, 6 for added, one for tag creation due usage of deployIT.

After rolling back I saw the behavior of removing all newly added 6 changesets even though one of the six changesets had an empty rollback tag.

Please any expert tell me why? What is the exact behavior of rollback?

Overall want to know when records from Databasechangelog removed ?

解决方案

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

If there is no <rollback> 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.

这篇关于回滚时,Liquibase遵循的所有步骤是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆