runOnChange
changeset attribute
The runOnChange
attribute executes the change the first time it is seen and each time the changeset is modified.
Liquibase determines that a changeset has been modified by comparing the MD5 checksum for the changeset to the checksum stored in the DATABASECHANGELOG table. If the runOnChange
attribute is not set or set to false, Liquibase will generate a checksum error if a changeset is modified after it has been deployed to a database. This is done to notify you that a changeset has been unexpectedly modified.
Uses
The runOnChange
attribute is useful for changesets that you would like to run each time they are modified. Common examples are Views
and Stored Procedures
that use the CREATE OR REPLACE
logic. If you copy the entire text of the stored procedure to a new changeset each time you make a change, you will not only end up with a very long changelog, but you will lose the merging and diff-ing power of your source control. Instead, put the text of the Stored Procedure
in a changeset with a runOnChange=”true”
attribute. The stored procedure will be recreated only when there is a change to the text.
Using runOnChange
The default value for runOnChange
is false. Set runOnChange
to true for changesets that should be executed whenever they are modified.
XML example
<changeSet author="your.name" id="changeset01" runOnChange="true" >
<createProcedure>
. . .
</createProcedure>
</changeset>
SQL example
--changeset your.name:changeset1 runOnChange:”true”
CREATE or REPLACE . . .
YAML example
changeset:
id: changeset1
author: your.name
runOnChange: “true”
changes:
. . .
JSON example
{ “changeSet” :
{“id”: changeset1,
“author”: your.name,
“runOnChange”: true,
“changes”:
[
. . .
]
}
}