创建时的 liquibase 约束参考 table

liquibase constraints references on create table

我正在从 Oracle 迁移到 Postgresql。 我们迁移到 Liquibase 已经有一段时间了,但并不是从一开始就迁移到 Liquibase。现在我正在努力添加和调整迁移以完全部署数据库并将数据传输到那里。

现在我遇到了这样一个问题,我没有创建一个 table,其中一个列的约束与另一个 table 相关联。由于在约束中 table 之前明确指定的方案,因此未采用此限制。

如何在未指定方案的tables的约束中指定使用默认方案?

使用 Maven 插件 liquibase-maven-插件 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)
)

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

你可以说

References: ist.ds_obj_opr(id)

但我猜你不认为那是优雅的……

或者,您可以将架构指定为参数,例如

References: ${schema}.ds_obj_opr(id)

如果你在任何地方都这样做,你可以使用DefaultSchemaName,而是在变更日志中使用<property>标签或-Dschema=ist 在调用期间。