Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

liquibase preconditions yaml

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

like image 214
Cifren Avatar asked May 28 '14 20:05

Cifren


People also ask

How do you add precondition to Liquibase?

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.

What is DB changelog master Yaml?

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.

What is Databasechangelog?

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.

What is runOnChange Liquibase?

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.


2 Answers

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
like image 63
pazfernando Avatar answered Sep 20 '22 13:09

pazfernando


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
like image 25
Matt Raible Avatar answered Sep 21 '22 13:09

Matt Raible