如何在 LiquiBase 约束中指定允许值列表?

How can I specify a list of allowable values in a LiquiBase constraint?

我有一个 table 我正在尝试使用 liquibase 创建。

在普通的旧 SQL 中,我会写

CREATE TABLE foo_bar (
  foo_bar_id    varchar2(40)   NOT NULL,
  is_foo        number(1)      NOT NULL,
  is_bar        number(1)      NOT NULL,
  CHECK (is_foo IN (0, 1)),
  CHECK (is_bar IN (0, 1)),
  PRIMARY KEY(foo_bar_id)
);

liquibase XML 中的(CHECK (is_foo IN (0, 1)) 语句的)等价物是什么?

Liquibase 目前不支持直接检查约束。您需要 运行 自定义 SQL 才能做到这一点:

<createTable name="foo_bar">
  .... here is the table definition without the check constraint
</createTable>
<sql splitStatements="false">
  alter table foo_bar 
    add constraint check_is_foo CHECK (is_foo IN (0, 1))
</sql>
<sql splitStatements="false">
  alter table foo_bar 
    add constraint check_is_bar CHECK (is_bar IN (0, 1))
</sql>