Liquibase 格式的 sql 前提条件表存在

yke*_*yev 1 mysql migration liquibase preconditions

基于 Liquibase xml 的变更集块:

<preConditions>
  <not>
    <tableExists tableName="alarm" schemaName="public"/>
  </not>
</preConditions>
Run Code Online (Sandbox Code Playgroud)

在“liquibase 格式的 sql”中应该如何?Liquibase 的官方文档只给出基于 xml 的

Jen*_*ens 5

用这个:

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

expectedResult是 liquibase 中的字符串,评估将进行字符串比较。因此,无论您的 sql 返回什么,都需要完全匹配(包括区分大小写)。

您还可以查看单元测试类FormattedSqlChangeLogParserTest以获取更多示例。