liquibase preconditions yaml

Cifren picture Cifren · May 28, 2014 · Viewed 9k times · Source

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...

Answer

pazfernando picture pazfernando · Mar 11, 2016

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