对多列进行复合非空检查的 Liquibase 条件

问题描述 投票:0回答:1

我有一个像 liquibase 中那样有 2 列的表。

              - column:
                  name: col1
                  type: UUID
                  constraints:
                    nullable: true
                    references: 'tab1(id1)'
                    foreignKeyName: 'fk_col1'
              - column:
                  name: col2
                  type: UUID
                  constraints:
                    nullable: true
                    references: 'tab2(id2)'
                    foreignKeyName: 'fk_col2'

我想对其中 2 列定义复合非空检查,至少 1 列非空。我发现这里回答了一个类似的查询:两列上的复合非空约束但是,这涉及添加

addCheckConstraint
https://docs.liquibase.com/change-types/add-check-constraint.html) )在 Postgresql 中。我们没有专业许可证,因此我们无法使用它,是否有其他方法可以添加此条件?

java sql spring-boot liquibase liquibase-sql
1个回答
0
投票
<changeSet id="uniqueId" author="yourname">
        <addCheckConstraint
            tableName="table_name"
            constraintName="chk_col1_or_col2_not_null"
            checkConstraint="col1 IS NOT NULL OR col2 IS NOT NULL"/>
</changeSet>
© www.soinside.com 2019 - 2024. All rights reserved.