Is it possible to use Precondition in YAML i didn't find any sources except this page http://www.liquibase.org/documentation/yaml_format.html
But I am looking for the equivalent of :
<changeSet id="addColumn-example">
<preConditions onFail="MARK_RAN">
<columnExists schemaName="earls"
tableName="category" columnName="display_name"/>
</preConditions>
<dropColumn columnName="display_name" schemaName="earls" tableName="category"/>
</changeSet>
So my natural translation will be :
changeSet:
id: addColumn-example
author: francis
preConditions:
- columnExist:
schemaName: earls
tableName: category
columnName: display_name
changes:
- addColumn:
columns:
- column:
name: display_name
type: varchar(100)
But i am missing onFail...
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 db/changelog/db.changelog-master.yaml file is the one executed on application startup when using default configuration. In that file you can have the sequential SQL changes as well as inclusions to other files.
Liquibase Concepts Simply put – a changelog contains an ordered list of changesets, and a changeset contains a change. You and your team can specify database changes in one of four different changelog formats: SQL, XML, JSON, or YAML. And, you can even mix and match different types of changelogs, if desired.
The runOnChange changeset attribute runs the change the first time it is detected 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.
this topic is poor documented, but after many tries... you can write something like this:
databaseChangeLog:
- changeSet:
id: 1
author: pazfernando
preConditions:
- onFail: MARK_RAN
- tableExists:
schemaName: sa
tableName: PROVEEDORBIENSERVICIO
changes:
- renameTable:
newTableName: PROVEEDORBIENSERVICIO
oldTableName: PROVEEDORSERVICIO
schemaName: sa
Here is another example with the sqlCheck
:
preConditions:
- onFail: CONTINUE
- onError: CONTINUE
- sqlCheck:
expectedResult: 0
sql: select count(*) from oss_organization where Status is null
- sqlCheck:
expectedResult: 0
sql: select count(*) from oss_organization where Type is null
The following seems to work:
databaseChangeLog:
- changeSet:
id: 1
author: mraible
preConditions:
onFail: MARK_RAN
not:
sequenceExists:
schemaName: public
sequenceName: hibernate_sequence
changes:
- createSequence:
sequenceName: hibernate_sequence
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