removeChangeSetProperty

The removeChangeSetProperty tag lets you remove column properties you previously specified in a changeset. This avoids errors when you deploy your changes on a database that doesn't support those properties. It is available in Liquibase 4.24.0+.

Uses

Some databases support column properties like afterColumn, beforeColumn, and position. You can specify these with the addColumn Change Type. For example, in an XML changelog:

<changeSet id="addColumn" author="mallod">
    <addColumn tableName="myTable">
        <column name="new_column" type="varchar(50)" afterColumn="test_col">
        </column>
    </addColumn>
</changeSet>

However, if you try to deploy this change to a database that doesn't support these properties, Liquibase returns an error.

To remove a property, add removeChangeSetProperty above your changesets. Liquibase replaces the property you specify with NULL and adds the new column to the end of the table. Now you can deploy without any errors.

Note: If your database supports additional column properties, you can still use removeChangeSetProperty to remove them.

Run removeChangeSetProperty

To run this Change Type, follow these steps:

  1. Add the Change Type to your changeset, as shown in the examples on this page.
  2. Specify any required attributes. Use the table on this page to see which ones your database requires.
  3. Deploy your changeset by running the update command:
  4. liquibase update

Attributes

Name Description Required for Supports
change The Change Type to modify. Valid values: addColumn all all
dbms

Specifies which database type(s) a changeset is to be used for. See valid database type names on Liquibase Database Tutorials. Separate multiple databases with commas. Specify that a changeset is not applicable to a particular database type by prefixing with !. The keywords all and none are also available.

all all
remove The property from addColumn to remove. Valid values: beforeColumn, afterColumn, position. Only removes a singles property. To remove more than one property, use an additional removeChangeSetProperty statement. all all

Examples

databaseChangeLog:
- removeChangeSetProperty:
    change: addColumn
    dbms: mysql, postgresql
    remove: afterColumn

- changeSet:
    id: addColumn-example
    author: liquibase-docs
    changes:
      - addColumn:
          tableName: myTable
          columns:
          - column:
              name: new_column
              type: varchar(50)
              afterColumn: test_col
{
    "databaseChangeLog": [
        {
            "removeChangeSetProperty": {
                "change": "addColumn",
                "dbms": "mysql, postgresql",
                "remove": "afterColumn"
            }
        },
        {
            "changeSet": {
                "id": "addColumn-example",
                "author": "liquibase-docs",
                "changes": [
                    {
                        "addColumn": {
                            "tableName": "myTable",
                            "columns": [
                                {
                                    "column": {
                                        "name": "new_column",
                                        "type": "varchar(50)",
                                        "afterColumn": "test_col"
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ]
}
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:pro="http://www.liquibase.org/xml/ns/pro"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
        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">

    <removeChangeSetProperty change="addColumn" dbms="mysql, postgresql" remove="afterColumn" />

    <changeSet id="addColumn-example" author="liquibase-docs">
        <addColumn tableName="myTable">
            <column name="new_column" type="varchar(50)" afterColumn="test_col-2">
            </column>
        </addColumn>
    </changeSet>

</databaseChangeLog>

Related links