How do I have to define a changeset in 'LiquiBase' notation for updating a table column whith an AND-ed WHERE-clause:
<changeSet id="ddl update tables : modify datatype for MY_TABLE.STATE_ABBREV" author="xxx">
<preConditions onFail="MARK_RAN" onFailMessage="Column MY_TABLE.STATE_ABBREV doesn't exists.">
<and>
<tableExists tableName="MY_TABLE"/>
<columnExists tableName="MY_TABLE" columnName="STATE_ABBREV"/>
</and>
</preConditions>
<update tableName="MY_TABLE">
<column name="STATE_ABBREV" value="AS"/>
<where>AGU /***AND STATE_ID=3***/ ??????????????????
</where>
</update>
</changeSet>
To generate a newer version of the changelog file with stored logic objects based on the current database state, you need to delete, rename, or move the Objects directory that was created by running the generate-changelog command previously. Then, you can run the generate-changelog command again.
You can use one <preConditions> tag per changeset and one overarching <preConditions> tag in the changelog (outside any changeset). In XML, YAML, and JSON changelogs, you can use conditional logic to add multiple preconditions within a single <preConditions> tag.
The changeset tag is a unit of change that Liquibase executes on a database and which is used to group database Liquibase Change Types together. A list of changes created by multiple changesets are tracked in a changelog.
What you put in the <where>
tag is simply appended to the end of the UPDATE statement after a " WHERE ". You can put anything in the where tag that you would normally put in SQL.
Example:
<changeSet id="ddl update tables : modify datatype for MY_TABLE.STATE_ABBREV" author="xxx">
<preConditions onFail="MARK_RAN" onFailMessage="Column MY_TABLE.STATE_ABBREV doesn't exists.">
<and>
<tableExists tableName="MY_TABLE"/>
<columnExists tableName="MY_TABLE" columnName="STATE_ABBREV"/>
</and>
</preConditions>
<update tableName="MY_TABLE">
<column name="STATE_ABBREV" value="AS"/>
<where>STATE_ABBREV IS NULL AND STATE_ID=3</where>
</update>
</changeSet>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With