TheMonkWhoSoldHisCode
TheMonkWhoSoldHisCode

Reputation: 2332

Does liquibase changeset ordering change on subsequent updates?

Is the CHANGESET execution in liqibase dependent on its position in the xml? For example if I have a the liquibase script as below

<changeSet id="20140211_001" author="test">
    <createTable tableName="alarm_notification_archive">
        <column name="id" type="bigint">
            <constraints nullable="false" />
        </column>

        <column name="event_timestamp" type="timestamp" defaultValue="0000-00-00 00:00:00">
            <constraints nullable="false" />
        </column>
    </createTable>
</changeSet>

<changeSet id="20140210_001" author="test">
    <sql>ALTER TABLE `notification_archive` ADD COLUMN
        `is_Alarm_Outstanding` BOOLEAN DEFAULT FALSE</sql>
    <rollback>
        <sql>ALTER TABLE notification_archive DROP COLUMN
            is_Alarm_Outstanding
                </sql>
    </rollback>
</changeSet>

My understanding is the changeset ordering is:

  1. 20140211_001
  2. 20140210_001

If I now add another changeset in between 1 and 2

<changeSet id="20140211_001" author="test">
    <createTable tableName="alarm_notification_archive">
        <column name="id" type="bigint">
            <constraints nullable="false" />
        </column>

        <column name="event_timestamp" type="timestamp" defaultValue="0000-00-00 00:00:00">
            <constraints nullable="false" />
        </column>
    </createTable>
</changeSet>

<changeSet id="20140212_001" author="test">
    <sql>ALTER TABLE `notification_archive` ADD COLUMN
        `is_Alarm_Outstanding` BOOLEAN DEFAULT FALSE</sql>
    <rollback>
        <sql>ALTER TABLE alarm_notification_archive DROP COLUMN
            is_Alarm_Outstanding
            </sql>
    </rollback>
</changeSet>

<changeSet id="20140210_001" author="test">
    <sql>ALTER TABLE `notification_archive` ADD COLUMN
        `is_Alarm_Outstanding` BOOLEAN DEFAULT FALSE</sql>
    <rollback>
        <sql>ALTER TABLE alarm_notification_archive DROP COLUMN
            is_Alarm_Outstanding
            </sql>
    </rollback>
</changeSet>

will the new changeset execution order be

  1. 20140211_001
  2. 20140212_001
  3. 20140210_001

Upvotes: 6

Views: 12217

Answers (2)

Dherik
Dherik

Reputation: 19060

Only to be more clear, Liquibase executes the changesets by the order in the file.

As explained here, the ID content does not make any effect in the execution order:

The id tag is only used as an identifier, it does not direct the order that changes are run and does not even have to be an integer.

Upvotes: 4

Mohammad Nadeem
Mohammad Nadeem

Reputation: 9392

Yes, Liquibase reads the changeSets in order. See the Changeset Documentation

Upvotes: 9

Related Questions