Liquibase Attributes ignore

Liquibase stores all database changes in the individual ChangeSet, the best practice is to specify only one type of change per ChangeSet record. Liquibase migrator executes ChangeSet sequentially, and only skips if preconditions, contexts or labels attributes are mentioned or if execution aborted due to error.

but some times requirement is to skip a ChangeSet, or certain ChangeSet should not run on Liquibase update, but should be in changelog file for tracking purpose. one way is to manually delete or comment out the ChangeSet and after updatation revert back to the original state, but this is very error-prone, to deal with this situation, Liquibase provides ignore attribute. ChangeSet with ignore attribute as true will be skipped by Liquibase migrator as it doesn't exist. by default ignore attribute has value as false.

changelog.mysql.sql

-- liquibase formatted sql

-- changeset :1692502428217-1
CREATE TABLE appledb.apple (apple_id BIGINT NOT NULL, apple_name VARCHAR(255) NULL, CONSTRAINT PK_APPLE PRIMARY KEY (apple_id));

-- changeset :1692502428217-2
INSERT INTO appledb.apple (apple_id, apple_name) VALUES (1, 'Macintosh');

-- changeset :1692502428217-3 ignore:true
INSERT INTO appledb.apple (apple_id, apple_name) VALUES (2, 'Fuji');

changelog.mysql.xml

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:pro="http://www.liquibase.org/xml/ns/pro"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
                        http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd
                        http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
    <changeSet author=" wesome (generated)" id="1692502413038-1">
        <createTable catalogName="appledb" tableName="apple">
            <column name="apple_id" type="BIGINT">
                <constraints nullable="false" primaryKey="true" />
            </column>
            <column name="apple_name" type="VARCHAR(255)" />
        </createTable>
    </changeSet>
    <changeSet author=" wesome (generated)" id="1692502413038-2">
        <insert catalogName="appledb" tableName="apple">
            <column name="apple_id" valueNumeric="1" />
            <column name="apple_name" value="Macintosh" />
        </insert>
    </changeSet>
    <changeSet author=" wesome (generated)" id="1692502413038-3" ignore="true">
        <insert catalogName="appledb" tableName="apple">
            <column name="apple_id" valueNumeric="2" />
            <column name="apple_name" value="Fuji" />
        </insert>
    </changeSet>
</databaseChangeLog>

changelog.mysql.yaml

databaseChangeLog:
  - changeSet:
      id: 1692502436866-1
      author:wesome (generated)
      changes:
        - createTable:
            catalogName: appledb
            columns:
              - column:
                  constraints:
                    nullable: false
                    primaryKey: true
                  name: apple_id
                  type: BIGINT
              - column:
                  name: apple_name
                  type: VARCHAR(255)
            tableName: apple
  - changeSet:
      id: 1692502436866-2
      ignore: true
      author:wesome (generated)
      changes:
        - insert:
            catalogName: appledb
            columns:
              - column:
                  name: apple_id
                  valueNumeric: 1
              - column:
                  name: apple_name
                  value: Macintosh
            tableName: apple
  - changeSet:
      id: 1692502436866-3
      author:wesome (generated)
      changes:
        - insert:
            catalogName: appledb
            columns:
              - column:
                  name: apple_id
                  valueNumeric: 2
              - column:
                  name: apple_name
                  value: Fuji
            tableName: apple

changelog.mysql.json

{
  "databaseChangeLog": [
    {
      "changeSet": {
        "id": "1692502447470-1",
        "author": "wesome (generated)",
        "changes": [
          {
            "createTable": {
              "catalogName": "appledb",
              "columns": [
                {
                  "column": {
                    "constraints": {
                      "nullable": false,
                      "primaryKey": true
                    },
                    "name": "apple_id",
                    "type": "BIGINT"
                  }
                },
                {
                  "column": {
                    "name": "apple_name",
                    "type": "VARCHAR(255)"
                  }
                }
              ],
              "tableName": "apple"
            }
          }
        ]
      }
    },
    {
      "changeSet": {
        "id": "1692502447470-2",
        "ignore": "true",
        "author": "wesome (generated)",
        "changes": [
          {
            "insert": {
              "catalogName": "appledb",
              "columns": [
                {
                  "column": {
                    "name": "apple_id",
                    "valueNumeric": 1
                  }
                },
                {
                  "column": {
                    "name": "apple_name",
                    "value": "Macintosh"
                  }
                }
              ],
              "tableName": "apple"
            }
          }
        ]
      }
    },
    {
      "changeSet": {
        "id": "1692502447470-3",
        "author": "wesome (generated)",
        "changes": [
          {
            "insert": {
              "catalogName": "appledb",
              "columns": [
                {
                  "column": {
                    "name": "apple_id",
                    "valueNumeric": 2
                  }
                },
                {
                  "column": {
                    "name": "apple_name",
                    "value": "Fuji"
                  }
                }
              ],
              "tableName": "apple"
            }
          }
        ]
      }
    }
  ]
}

liquibase.properties (update changeLogFile file format with SQL, XML, YAML, JSON as per changelog.mysql.<format>)

changeLogFile=changelog.mysql.xml
liquibase.command.url:jdbc:mysql://localhost:3306/AppleDb?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true
liquibase.command.username: root
liquibase.command.password: rootroot

follow us on