Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

liquibase constraints references on create table

I'm migrating from Oracle to Postgresql. We have been migrating to Liquibase for some time, but not from the very beginning. Now I'm working on adding and adapting migrations to fully deploy the database and transfer the data there.

Now I encountered such a problem that I do not create a table with a column that has a constraint associated with another table. This restriction is not picked up because of the explicitly specified scheme before the table in the constraint.

How to specify that in the constraints for tables with an unspecified scheme, the default scheme was used?

Using Maven Plugin liquibase-maven-plugin 3.5.3

Here are the Properties:

Url: jdbc: postgresql: //192.168.1.1: 5432 / postgres
DefaultSchemaName: ist
ReferencedTableSchemaName: ist
Username: test
Password: 123
Verbose: true
DropFirst: false

Here is the migration piece

 - 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

Migration generates such a request:

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

Tell me how to solve this problem elegantly. Thank you.

like image 610
Alex Avatar asked Nov 24 '25 23:11

Alex


1 Answers

You can say

References: ist.ds_obj_opr(id)

But I guess you don't count that as elegant…

Alternatively, you could specify the schema as parameter, like

References: ${schema}.ds_obj_opr(id)

If you do that everywhere, you could not use DefaultSchemaName, but rather specify the schema with a <property> tag in the changelog or with -Dschema=ist during invocation.

like image 192
Laurenz Albe Avatar answered Nov 26 '25 16:11

Laurenz Albe