gpt4 book ai didi

postgresql - 创建表上的 liquibase 约束引用

转载 作者:行者123 更新时间:2023-11-29 12:25:07 26 4
gpt4 key购买 nike

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

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

如何在未指定scheme的表的约束中指定使用默认scheme?

使用 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 的标记在调用期间。

关于postgresql - 创建表上的 liquibase 约束引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44224441/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com