liquibase约束对create table的引用

时间:2017-05-28 06:25:53

标签: postgresql maven migration constraints liquibase

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

现在我遇到了一个问题,我没有创建一个包含与另一个表关联的约束的表。由于在约束中的表之前明确指定了方案,因此不会获取此限制。

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

使用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)
)

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

1 个答案:

答案 0 :(得分:0)

你可以说

References: ist.ds_obj_opr(id)

但我猜你不算那么优雅......

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

References: ${schema}.ds_obj_opr(id)

如果您在任何地方都这样做,您可以使用DefaultSchemaName,而是在更改日志中使用<property>标记或在-Dschema=ist期间指定架构。调用