Applies to:
- Liquibase Pro
Summary:
Liquibase Pro has additional rollbacks features that give more control when rolling back changes:
- rollback-one-changeset
- rollback-one-update
- rollback-to-date
Environment Conditions:
- Liquibase with a valid Pro license
How to Implement a Rollback
It is a good practice to review and run the corresponding SQL version of the command to check what the command will roll back. Each of the Pro rollback commands requires the --force flag.
Each example below will use the following changeset with deployment ID 068379006 and deployed on October 5th, 2022.
-- liquibase formatted sql
-- changeset userName:1
CREATE TABLE Table_1 (Name VARCHAR (50), Country VARCHAR (50));
--rollback DROP TABLE Table_1;
Example: rollback-one-changeset
liquibase rollback-one-changeset --changeset-author="userName" --changeset-id="1" --changeset-path=changelog.xml --force
Note: The changeset path is the path from the changelog to the changeset. In this case, the changeset is located in the changelog.xml file. But if you have a main changelog file that calls a SQL file with the changeset that you want to roll back, that path to the changeset needs to be used.
Example: rollback-one-update
liquibase rollback-one-update --deploymentId=068379006 --force
A deployment ID is generated and assigned to all changesets deployed with the update command.
For example, if you run an update command with 10 new changesets, each of those will share the same deployment ID. However, if the next deployment only has 3 new changesets, those 3 will have the same deployment ID, which will differ from the deployment ID with the first 10 changesets.
Example: rollback-to-date
liquibase rollback-to-date 2022-10-05
There are several ways to revert your changes with the rollback-to-date command. You can use the YYYY-MM-DD HH:MM:SS or YYYY-MM-DD'T'HH:MM:SS formats to specify both date and time. You can also specify a date or time only.
In the example above, we specify the date to rollback, and any changeset that matches that date in the DATABASECHANGELOG table will be rolled back.
Comments
0 comments
Article is closed for comments.