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