Rollback by tag doesn't roll back tagDatabase changeSet
Description
Environment
All
Activity
Elber Gomez October 17, 2018 at 8:55 PM
I also agree with Adam. Rolling back to a specific tag should leave the DB in the state it was when the tag was applied (including the tag record being present in the changelog table).
In the example given above, the sequence should be inverted. The CS1 tag should be applied after table a_test1 is added.
So for example, if I have the following sequence of changesets applied on a DB:
1. Add table ABC
2. Tag db as v1.0
3. Add table XYZ
4. Add some columns
5. Tag db as v2.0
If I want to rollback to v1.0 by running command "rollback v1.0" , I expect liquibase to revert changesets 5, 4 and 3, leaving changesets 1 and 2 alone. And both left in the changelog table.
This would be consistent with the description of the rollback <tag> action as per documentation:
"rollback <tag>: Rolls back the database to the state it was in when the tag was applied."
Adam Gardner July 20, 2018 at 10:10 PM
I disagree with the original reporter's logic here; the 'rollback' action states that it "Rolls back the database to the state it was when the tag was applied", not "the state it was before the tag was applied". Moreover, as shows, a lot of people rely on tags to indicate the current status of their database; removing the tag after rolling back to it means this is no longer possible.
Nathan Voxland July 6, 2016 at 5:17 PM
Fixed.
However, if there is more in a changeSet besides the tagDatabase command it we cannot unmark it as ran. You really shouldn't have non-tagDatabase commands mixed with tagDatabase in a changeSet but if you do the old logic will still hold: it will roll back everything after the changeSet with the tagDatabase change in it but will leave that changeSet marked as ran.
If you have a changeLog like:
<changeSet author="tester" id="1">
<tagDatabase tag="CS1"/>
</changeSet>
<changeSet author="tester" id="2">
<createTable tableName="a_test1">
<column name="id" type="int"/>
<column name="name" type="varchar(50)"/>
<column name="city" type="varchar(50)"/>
<column name="last_name" type="varchar(50)"/>
</createTable>
</changeSet>
and update then "rollback CS1" the ending databasechangelog table will still have a row for tagDatabase.
Running rollback to a tag should bring the changelog table back to the state it was when the tag was applied. In this case, the tagDatabase command should no longer be there because that was marked as ran after the tag was applied.