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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With