Liquibase在创建表时添加引用约束

3
我正在从Oracle迁移到PostgreSQL。我们一直在迁移到Liquibase,但不是从一开始。现在我正在添加和调整迁移以完全部署数据库并将数据传输到那里。
现在我遇到了这样一个问题,即无法创建具有与另一个表关联的约束的列的表。由于在约束中指定了显式方案,因此不会选择此限制。
如何指定对于未指定方案的表的约束使用默认方案?
使用Maven插件liquibase-maven-plugin 3.5.3
以下是属性:
Url: jdbc: postgresql: //192.168.1.1: 5432 / postgres
DefaultSchemaName: ist
ReferencedTableSchemaName: ist
Username: test
Password: 123
Verbose: true
DropFirst: false

这里是迁移文档

 - createTable:
        TableName: opr_possibilities
        Remarks: Operator capability map
        Columns:
        - column:
            Name: id
            Type: number (11)
            Remarks: ID
            Constraints:
              Nullable: false
              PrimaryKey: true
        - column:
            Name: operator_id
            Type: number (11)
            Remarks: Operator ID
            Constraints:
              Nullable: false
              ForeignKeyName: fk_possibility_operator
              References: ds_obj_opr (id)
# ReferencedTableName: ds_obj_opr
# ReferencedColumnNames: id

迁移会生成这样的请求:

CREATE TABLE ist.opr_possibilities (
      id numeric(11) NOT NULL, 
      operator_id numeric(11) NOT NULL, 
      begin_date date DEFAULT NOW() NOT NULL, 
      end_date date DEFAULT NOW() NOT NULL, 
      duty BOOLEAN DEFAULT FALSE NOT NULL, 
      status numeric(4) DEFAULT 0 NOT NULL, 
      type numeric(4) DEFAULT 0 NOT NULL, 
      remarks VARCHAR(255), 
      CONSTRAINT PK_OPR_POSSIBILITIES PRIMARY KEY (id), 
      CONSTRAINT fk_possibility_operator FOREIGN KEY (operator_id) REFERENCES ds_obj_opr(id)
)

告诉我如何优雅地解决这个问题。谢谢。
1个回答

1

你可以说

References: ist.ds_obj_opr(id)

但我猜你不会把那个算作优雅的方式...

或者,你可以将模式指定为参数,像这样

References: ${schema}.ds_obj_opr(id)

如果你在每个地方都这样做,你可以不使用DefaultSchemaName,而是在changelog中使用标签或在调用时使用-Dschema=ist来指定模式。

是的,你说得对,我没有把这些决定考虑得很优雅。但我认为这个问题是一个错误。 为什么不使用"defaultSchemaName"来做"references"? 就像"addForeignKeyConstraint"中的"constraintName"一样,并没有注意"objectQuotingStrategy"="QUOTE_ALL_OBJECTS"但现在我通过一个变量来应用模式指定,因为我们的迁移中使用了原生查询。但还是谢谢你的回答) - Alex

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接