Liquibase formatted sql precondition tableExists

Liquibase xml based changeset block:

    <tableExists tableName="alarm" schemaName="public"/>

How it should be in "liquibase formatted sql"? Official documentation of Liquibase give only xml based

1 answer

  • answered 2018-07-11 08:47 Jens

    Use this:

    --preconditions onFail:HALT onError:HALT
    --precondition-sql-check expectedResult:0 SELECT count(*) FROM information_schema.tables where table_name = 'alarm';

    The expectedResult is a String in liquibase and the evaluation will do a String comparsion. So whatever your sql returns needs to match exactly (including case sensitivity).

    You can also check the unit test class FormattedSqlChangeLogParserTest for further examples.