Liquibase 先决条件失败自定义错误消息

Liquibase preconditions failure custom error message

我有一个变更集

<changeSet id="ABC123" author="davnicwil">
  <preConditions onFail="HALT">
    <sqlCheck expectedResult="3">SELECT count(*) FROM little_pigs</sqlCheck>
  </preConditions>
  <sql>DROP TABLE wolf</sql>
</changeSet>

little_pigs 中只有 2 行时,它失败并显示此错误消息

liquibase.exception.MigrationFailedException: 
  Migration failed for change set migrations.xml::ABC123::davnicwil:
    Reason: 
      migrations.xml : SQL Precondition failed.  Expected '3' got '2'

我想要更有意义的错误信息,例如

liquibase.exception.MigrationFailedException: 
  Migration failed for change set migrations.xml::ABC123::davnicwil:
    Reason: 
      3 little pigs are required to defeat the wolf

有什么方法可以配置这样的自定义错误消息,以满足前提条件?

静态消息就可以了。如果可以动态消息就更好了。

我认为

onFailMessage   Custom message to output when preconditions fail. Since 2.0

(http://www.liquibase.org/documentation/preconditions.html) 是静态消息所需要的。我没有得到你对 "dynamic message" 的期望,但你可以使用 <customPrecondition>

来实现你自己的逻辑