两个表之间的 Liquibase 检查约束

问题描述

我想创建两个新列,每个列都在不同的表中。 例如:在 company 表上,我想在 employee 上创建一个名为 last_registration_number 的列和名为 registration_number 的第二列strong> 带有检查约束的表,遵循此逻辑

 registration_number of employee table <= last_registration_number of company table

我找不到如何在两个表之间执行此操作。 这样做的正确方法是什么?

解决方法

我想 Liquibase PRO 版本可以提供帮助。它有 addCheckConstraint 标签(以及编辑和删除)。这是 description 的链接。

checkConstraint 标签中还有一个 constraints 属性:

<createTable tableName="foo">
    <column name="bar" type"integer">
        <constraints checkConstraint="your condition here"/>
    </column>
</createTable>

但我不确定它是否会起作用,因为拉取请求 basics of implementing checkConstraint 仍处于打开状态。

或者,如果您可以随意使用 sql 标签,它允许您在纯 SQL 中执行任何您想做的事情。