Search code examples
liquibaseliquibase-sqlliquibase-cli

Liquibase can't rollback to any tag


Running liquibase rollback --tag=1

Gives this error:

Liquibase Open Source 4.27.0 by Liquibase
ERROR: Exception Details
ERROR: Exception Primary Class:  RollbackFailedException
ERROR: Exception Primary Reason:  Could not find tag '1' in the database
ERROR: Exception Primary Source:  4.27.0

Unexpected error running Liquibase: Could not find tag '1' in the database

The changelog looks like this:

-- liquibase formatted sql

-- changeset Jota:1
CREATE TABLE IF NOT EXISTS "Tabela1" ();

-- changeset Jota:tag_before_alter_table
-- tag

-- changeset Jota:2
ALTER TABLE "Tabela1" ADD COLUMN IF NOT EXISTS id INT;

In pgadmin i can see TABLE databasechangelog has 3 entries with IDs "1", "tag_before_alter_table" and "2" as it should.

Am i doing something wrong?

I already tried reseting the databasechangelog table, but didn't work


Solution

  • Could not find tag '1' in the database indicates that there is no such tag in the databasechangelog.tag column. That's because tagging is not supported in SQL notation.

    What Liquibase tag does is update databasechangelog.tag column which corresponds with the changeSet you want to tag.

    So you can do tagging manually:

    --changeset author:id -tag:"1"
    UPDATE databasechangelog SET tag='1' WHERE ID = {id of the changeSet you want to tag}