Reputation: 133
my problem is that liquibase is not rolling back some of my changesets that have been executed after a tag was set on the change set i am trying to rollback too.
For example I have created two changesets (A and B) which execute as normal. and then i have created another changeset which sets the tag of changeset B to release1. and this changeset also works as expected. however i then execute another 5 changesets all with rollback commands. and these also execute fine.
Now the problem comes when i run the following:
java -jar liquibase.jar --changeLogFile=..\database\changelog-create.xml rollback release1
Now shouldn't this rollback any changesets that were executed after the release1 tag was executed?
If so, this is my problem, they are not being rolled back. but in console i get Rollback was successful.
Upvotes: 2
Views: 3102
Reputation: 1454
For those who will face with similar issues, here is a detailed explanation:
During rollback liquibase compares given parameters with appropriate parameters from a databasechangelog table.
Imagine we are going to invoke a rollback. And we would like to do that outside of a project directory. So, we have the next command:
liquibase --url="some-jdbc-url" --changelog-file="/some/path/to/the/db/changelog/changelog-1.json" --username=someusername --password=somepassword rollback-count 1
and also we have the next content in our databasechangelog table:
| id | author | filename | dateexecuted |orderexecuted|exectype| md5sum | description |comments|tag|liquibase|contexts|labels|deployment_id|
|-------|-----------|------------------------------|-----------------------|-------------|--------|----------------------------------|----------------|--------|---|---------|--------|------|-------------|
|some-id|some-author|/db/changelog/changelog-1.json|2022-12-29 10:00:00.000| 1 |EXECUTED|8:2645faaa8ad312262c8dc1111eeeeeee|some-description| | | 4.18.0 | | | 1112233445 |
Please note, that a file name in the table is different (e.g. because changelogs were invoked within a project directory during a startup)
So, in this case rollback will not have an effect although Liquibase command 'rollback-count' was executed successfully
is printed.
It happens because provided changelog path in the rollback command and a path in the table are not equal:
(/some/path/to/the/db/changelog/changelog-1.json
and /db/changelog/changelog-1.json
).
They must be equal
To fix that problem we need to go to the appropriate directory, so our path to the changelog becomes the same. In our example we should go to /some/path/to/the
and invoke next command:
liquibase --url="some-jdbc-url" --changelog-file="/db/changelog/changelog-1.json" --username=someusername --password=somepassword rollback-count 1
Now, since --changelog-file
value and filename
value are equal, rollback makes changes.
So, during your investigtions please put attention on parameters matching (between provided in a command and in a databasechangelog table). Check provided changelog path, calculated checksums, authors and so on.
Upvotes: 2
Reputation: 133
So I found the problem.. The following line in my command line
--changeLogFile=..\database\changelog-create.xml
Was wrong. The changeLogFile should be the one you want to start the rollback from. Whereas i provided the changelog file with the tag.
Upvotes: 1