Rollback issue when using --labels

This is my below change set in xml format:




SELECT COUNT(*) FROM accounting_dflts WHERE id = 220;


    <sql>
        INSERT INTO `accounting_dflts` (`id`,`ACCOUNTING_EVENT`,`EVENT_TYPE`,`SEGMENT_SEQUENCE`,`SEGMENT_NAME`,`DERIVED`,`DEFAULT_VALUE`,`SEPERATION_OP`) VALUES (220,'RECLASS','CREDIT',8,'Company','Y',NULL,'.');
    </sql>

    <rollback>
        <sql>
            DELETE FROM `accounting_dflts` WHERE `id` = 220;
        </sql>
    </rollback>
</changeSet>

I am able to do “liquibase update --labels=”, but when I am doing rollback “liquibase rollback --labels=release_16.b-4”, I am getting this error: “Error parsing command line: Invalid argument ‘–tag’: missing required argument”. As I am new to Liquibase , please help me how to rollback ? do I need to update any thing in my change set ? please advise

Please edit your post to include the entire .xml file contents, only partial is showing.

<?xml version="1.0" encoding="UTF-8"?>

<changeSet id="2024_06_03_01" author="Ranjit" labels="release_16.b-2">
    <sql>
        INSERT INTO `accounting_dflts` (`id`,`ACCOUNTING_EVENT`,`EVENT_TYPE`,`SEGMENT_SEQUENCE`,`SEGMENT_NAME`,`DERIVED`,`DEFAULT_VALUE`,`SEPERATION_OP`) VALUES (127,'RECLASS','CREDIT',8,'Company','Y',NULL,'.');
    </sql>

    <rollback>
        <sql>
            DELETE FROM `accounting_dflts` WHERE `id` = 127;
        </sql>
    </rollback>
</changeSet>

<changeSet id="2024_06_04_01" author="Patt" labels="release_16.b-4">
    <sql>
        INSERT INTO `accounting_dflts` (`id`,`ACCOUNTING_EVENT`,`EVENT_TYPE`,`SEGMENT_SEQUENCE`,`SEGMENT_NAME`,`DERIVED`,`DEFAULT_VALUE`,`SEPERATION_OP`) VALUES (220,'RECLASS','CREDIT',8,'Company','Y',NULL,'.');
    </sql>

    <rollback>
        <sql>
            DELETE FROM `accounting_dflts` WHERE `id` = 220;
        </sql>
    </rollback>
</changeSet>

First thing I notice is that you are using sql tags inside the rollback section. This is not needed. Sql should be used directly inside the rollback tags:

<rollback>
        DELETE FROM `accounting_dflts` WHERE `id` = 127;
</rollback>

<rollback>
        DELETE FROM `accounting_dflts` WHERE `id` = 220;
</rollback>

I’d try that first.

I am running this rollback inside docker container through Azure pipeline.
docker run --network=“host”
-v $(System.DefaultWorkingDirectory)/changelog-rds.xml:/workspace/changelog-rds.xml
“$FULL_ECR_REPOSITORY”
–url=“jdbc:mysql://127.0.0.1:$MYSQL_PORT/$MYSQL_DATABASE”
–changeLogFile=./changelog-rds.xml
–username=“$MYSQL_USER” --password=“$SECRET”
rollback-count --count=1
If I am using rollback-count --count=1 , it is working but when I am trying both option ( rollback --labels=release_16.b-4 and rollback --label-filter=release_16.b-4 ) , it is not working. Kindly have a look.

Could you please help me on this. I am stuck with rollback. No further progress on my poc. Your help is much appreciate.

(I will preface this by saying that I do not use the Liquibase Docker image, so I do not know the particulars of using it. I only the Liquibase CLI.)

There are 3 rollback commands. Each one requires a parameter that indicates where to “stop” the rollback.

  1. rollback
  2. rollback-to-date
  3. rollback-count

I don’t see a tag being provide when you are running rollback.

More details here: Liquibase Rollback Workflow

Thank you for update. I have another query as I am running liquibase using cli in windows 11 machine.
This is my liquibase.properties file:
url=jdbc:mysql://dev.xxxxx.us-east-1.rds.amazonaws.com:3306/test1
username=
password=
driver=com.mysql.cj.jdbc.Driver
classpath=D:\project_2\mmapp\mysql-connector-j-8.4.0.jar
changeLogFile=D:\project_2\mmapp\migrations\changelog-rds\changelog-rds.json

When I running liquibase status , I am getting this error:
Liquibase Open Source 4.27.0 by Liquibase
ERROR: Exception Details
ERROR: Exception Primary Class: ChangeLogParseException
ERROR: Exception Primary Reason: D:\project_2\mmapp\migrations\changelogrds\changelog-rds.json does not exist

But when I checked I am able to see the file:
D:\project_2\mmapp>dir “D:\project_2\mmapp\migrations\changelogrds\changelog-rds.json”
Volume in drive D is Data
Volume Serial Number is 36A3-6E65

Directory of D:\project_2\mmapp\migrations\changelogrds

06/06/2024 03:51 PM 536 changelog-rds.json

I tried both way to run:
liquibase --changeLogFile=D:\project_2\mmapp\migrations\changelog-rds\changelog-rds.xml status

and

liquibase status . Please help me.

Please review this documentation:

Thank you.
I have one query. I am doing rollback-to-date command to execute. But I am getting zero change set update.

This is command I am using:
liquibase rollback-to-date 2024-06-11 19:32:12

this date value I am taking from this column DATEEXECUTED from DATABASECHANGELOG table.

From log:
INFO: 0 changesets rolled back.
Liquibase command ‘rollback-to-date’ was executed successfully.

Please help me? This date format what Liquibase expects ?

Date formats are documented here:

I would use a date before the oldest chngeset you want to rollback.

Many thanks for reply. I have one doubt here. Kindly guide me.

This is below data from my DATABASECHANGELOG table. I want to rollback last applied change for ranjit. When I passed DATEEXECUTED as 2024-06-12 12:00:41 , I am getting zero changeset rolled back. But when I passed this DATEEXECUTED as 2024-06-12 11:54:54, then only ranjit’s changeset has been rolled back. So I can not do roll back to specific DATEEXECUTED? as below I always passed previous DATEEXECUTED as below? Please guide me.

2023_10_31_01 karthik changelog-rds.json 2024-06-12 11:54:49 1
2023_10_31_02 karthik changelog-rds.json 2024-06-12 11:54:52 2
2023_05_21_03 karthik changelog-rds.json 2024-06-12 11:54:53 3
2023_11_09_01 saura changelog-rds.json 2024-06-12 11:54:54 4
2024_06_04_01 ranjit changelog-rds.json 2024-06-12 12:00:41 5

liquibase rollback-to-date --date=“2024-06-12 12:00:41”
o/p:-
INFO: 0 changesets rolled back.
Liquibase command ‘rollback-to-date’ was executed successfully.

liquibase rollback-to-date --date=“2024-06-12 11:54:54”
o/p:
Rolling Back Changeset: changelog-rds.json::2024_06_04_01::ranjit
Liquibase command ‘rollback-to-date’ was executed successfully.

If you want to rollback the changeset “2024_06_04_01 ranjit changelog-rds.json” you need to provide a timestamp before that changeset was applied, like:

“2024-06-12 12:00:40” or “2024-06-12 12:00:00”

You are asking Liquibase to rollback to a point-in-time. If you provide the timestamp when then changeset was applied, then the changeset will stay.

Thank you. Your help is really appreciate. So we can not roll back to specific date from DATEEXECUTED column. We need to pass a timestamp before that chageset was applied. Thank you again for quick reply with answer.

1 Like

I am using AWS DocumentDB to apply Liquibase commands. Below is the dateExecuted column value from the DATABASECHANGELOG collection:

dateExecuted
2024-06-29T20:43:12.808Z - Change set 1
2024-07-01T14:28:10.074Z - Change set 2
2024-07-01T14:28:10.168Z - Change set 3
2024-07-01T14:28:10.302Z - Change set 4

I have two new change sets. Before applying the Liquibase command, I retrieved the last applied dateExecuted value: “2024-07-01T14:28:10”.

Out of the two new change sets, the first one applied successfully, but the second change set encountered an issue. So, we are applying a rollback using the command:

liquibase rollback-to-date --date=2024-07-01T14:28:10

Since the first new change set succeeded and the second one failed, we applied a rollback. However, this rollback also reverted the old change sets along with the new one. Specifically, it rolled back these change sets:

2024-07-01T14:28:10.074Z - Change set 2
2024-07-01T14:28:10.168Z - Change set 3
2024-07-01T14:28:10.302Z - Change set 4

I do not want the old change sets to be rolled back. How can I prevent this?

While passing the date value “2024-07-01T14:28:10”, can I increase it by one second to “2024-07-01T14:28:11” and then apply the rollback? Will this prevent the issue?

Alternatively, do you have any other suggestions?

Many thanks for your help and suggestions so far.

Hello daryldoak, Could you please help me above post ?. Many thanks for help

According to the “rollback-to-date” documentation, you can only specify date and time when using rollback-to-date.

YYYY-MM-DD HH:MM:SS or YYYY-MM-DD'T'HH:MM:SS

The issue is that your changesets 2, 3, and 4 are all the same date and time.

Therefore, rollback-to-date is not going to work for this rollback.

I think the best option for this scenario is to use the “rollback-count” command, where you specify the number of changesets to rollback. In your case “rollback-count 2”.

Try that.

Thank you daryldoak.
In my code, I am using the following approach:

DATE_EXECUTED=“2024-07-02T17:15:56”
DATE_EXECUTED_PLUS_ONE=$(date -u -d “${DATE_EXECUTED}Z +1 second” +“%Y-%m-%dT%H:%M:%S”)
echo “Rollback to date: $DATE_EXECUTED_PLUS_ONE” # Output: 2024-07-02T17:15:57

liquibase rollback-to-date --date=$DATE_EXECUTED_PLUS_ONE

This means that any changes deployed after “2024-07-02T17:15:57” will be rolled back.And I tested its working.

Can you please confirm if this approach is correct for using the liquibase rollback-to-date command?

yes, that approach looks generally good, but that approach won’t solve the issue in your original scenario, where all 3 are in the same second.