0

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 ?

Verhagen
  • 3,885
  • 26
  • 36
Nagappa L M
  • 1,452
  • 4
  • 20
  • 33
  • The expected behaviour of liquibase rollback if one changeset does not incluye a is to fail. This deployIT you comment is a tool that uses liquibase underneath? have you try to execute rollback using liquibase command ex: liquibase rollbackCount 3 – kothvandir Jan 11 '17 at 07:49

2 Answers2

3

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.

Nathan Voxland
  • 15,453
  • 2
  • 48
  • 64
  • If Liquibase removes changesets having empty rollback tag from databasechangeLog table after executing rollback no need to scare rite ?.It is just removing changesets entries from table,not executing any not-mentioned scripts as action to rollback ? rite ?.Thank you very much for your time. – Nagappa L M Jan 12 '17 at 05:58
  • Yes, if you have an empty rollback on something that could auto-rollback like createTable, the databasechangelog entry will just be deleted and no other changes made. – Nathan Voxland Jan 13 '17 at 04:24
0

Depending on your change sets, may be you fall in case of statements having rollback commands generated automatically, as for Liquibase Rollback documentation:

Many refactorings such as “create table”, “rename column”, and “add column” can automatically create rollback statements. If your change log contains only statements that fit into this category, your rollback commands will be generated automatically.

Other refactorings such as “drop table” and “insert data” have no corresponding rollback commands that can be automatically generated. In these cases, and cases where you want to override the default generated rollback commands, you can specify the rollback commands via the tag within the changeSet tag. If you do not want anything done to undo a change in rollback mode, use an empty tag.

At http://forum.liquibase.org/topic/understanding-rollback you can find more details and other links.

gile
  • 5,580
  • 1
  • 25
  • 31