liquibase preconditions yaml

白昼怎懂夜的黑 提交于 2019-12-10 15:13:35

问题


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


回答1:


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

I hope it helps... bye




回答2:


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



回答3:


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.




回答4:


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"



回答5:


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.



来源:https://stackoverflow.com/questions/23921460/liquibase-preconditions-yaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!