Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatted SQL With PreConditions

Tags:

liquibase

I'm on Liquibase Version: 2.0.1.

Is it possible to have pre-conditions in a formatted sql file? If so how? An example would be appreciated.

I would like to do somthing like this but in sql formatted file.

 <preConditions onFail="WARN"> 
    <sqlCheck expectedResult="0">select count(*) from oldtable</sqlCheck> 
 </preConditions>
like image 769
Kuberchaun Avatar asked Mar 10 '11 15:03

Kuberchaun


2 Answers

Specifying preconditions in a liquibase formatted sql file is now supported. Within a changeset definition, the preconditions may be specified using the following format (copied from the official docs):

--preconditions onFail:HALT onError:HALT
--precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM my_table

It is noted in the documentation that only the sql check precondition type is supported at this time.

Complete documentation is available at the liquibase website.

like image 178
Ron Dahlgren Avatar answered Nov 09 '22 05:11

Ron Dahlgren


Outdated: The feature has been added in latest Liquibase version. See https://stackoverflow.com/a/27494608/256561 for up to date solution.

Unfortunately, the current FormattedSql parser does not support preconditions.

You could extend the default class with your own parser that would support it if you need, however. See http://liquibase.org/extensions

like image 42
Nathan Voxland Avatar answered Nov 09 '22 04:11

Nathan Voxland