liquibase preconditions yaml
Asked Answered
P

5

11

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

Panelist answered 28/5, 2014 at 20:41 Comment(2)
Did you ever figure out an answer for this? I'm to do the same thing, but can't figure out how to do onFail: MARK_RAN.Rattrap
For what I remember from this issue (in 2014), it was simply not possible with YAML, I had to do it with XML. But maybe with the new version it should be working now.Panelist
M
27

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
Memorial answered 11/3, 2016 at 1:11 Comment(1)
Everything in liquibase is poorly documentedGuillermo
R
8

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
Rattrap answered 3/10, 2014 at 20:43 Comment(1)
actually this is the correct syntax. It is a double negation. *Exists is returning true, but the MARK_RAN is onFail so the not: is needed to negate the response to false to meet onFail condition. Sadly there is no onSuccess :(Leroylerwick
M
2

Syntax for sqlCheck condition:

databaseChangeLog:
- changeSet:
    id: changeSet-id
    author: myName
    preConditions:
      - onFail: MARK_RAN
      - sqlCheck:
          expectedResult: 1
          sql: "select count(*) from foo where some-condition"
    changes:
      - sql: "your sql script"
Mcginnis answered 25/9, 2018 at 14:7 Comment(0)
N
1

It is probably something that didn't work with Liquibase 3.1.x but should work in the just-released 3.2.0 version. Your example changeSet should be right.

Nevarez answered 2/6, 2014 at 20:23 Comment(0)
T
0

DBMS precondition

databaseChangeLog:
  - changeSet:
      id: 1
      author: yourname
      dbms: oracle,h2
      changes:
        - sql: "your sql script"

As you can see, this is not a real precondition, but I found it to be working similar: the changeset is ignored if the database type is not matching.

Tuttifrutti answered 18/11, 2019 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.