Ora2Pg v25 generates invalid foreign keys for Oracle reference partitions when DISABLE_PARTITION is enabled
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
Research direction
Start by reading _create_foreign_keys and comparing its partition-key handling with other logic guarded by disable_partition. Reproduce the TYPE TABLE export with DISABLE_PARTITION 1 and verify the generated foreign key uses only the child FK columns and that PostgreSQL accepts the schema.
Written by the indexing model from the issue text.
Description
Summary
Ora2Pg v25 can generate invalid PostgreSQL foreign key DDL for Oracle schemas that use reference partitioning when the migration is configured with DISABLE_PARTITION 1.
The generated child-table foreign key may include the parent table partition key even though that column does not exist on the child table. PostgreSQL then rejects the generated schema SQL with:
ERROR: column "<partition_key_column>" referenced in foreign key constraint does not exist
Environment
- Ora2Pg: v25.0
- Export type:
TYPE TABLE - PostgreSQL target: PostgreSQL 16
- Relevant Ora2Pg settings:
DISABLE_PARTITION 1PG_VERSION 16
Generic Reproduction Shape
Oracle metadata:
- Parent table is partitioned by a range/list/hash partition key.
- Child table is reference-partitioned through a foreign key to the parent table.
- The child foreign key is logically defined only on the child FK column, for example:
CHILD_TABLE(PARENT_ID) -> PARENT_TABLE(ID)
- The child table does not contain the parent partition key column.
Expected PostgreSQL DDL when partitions are disabled:
ALTER TABLE child_table
ADD CONSTRAINT fk_child_parent
FOREIGN KEY (parent_id)
REFERENCES parent_table(id);
Actual PostgreSQL DDL generated by Ora2Pg v25:
ALTER TABLE child_table
ADD CONSTRAINT fk_child_parent
FOREIGN KEY (parent_id, parent_partition_key)
REFERENCES parent_table(id, parent_partition_key);
This fails because parent_partition_key is not a column on child_table.
Suspected Root Cause
In _create_foreign_keys, Ora2Pg appends partition key columns from partitions_list to the local and remote FK column lists. That logic appears to run even when DISABLE_PARTITION 1 is enabled.
When partitions are flattened into regular PostgreSQL tables, the partition key should not be appended to the generated FK. Similar partition-aware logic in other parts of Ora2Pg is guarded by !$self->{disable_partition}.
Proposed Fix
Guard the partition-key append block in _create_foreign_keys with:
if (!$self->{disable_partition}) {
...
}
This keeps FK generation aligned with flattened table DDL when DISABLE_PARTITION 1 is used.
Why Workarounds Are Not Sufficient
Per-constraint FKEY[...] excludes remove the broken DDL, but they require manual analysis for every schema and can silently drop useful constraints. Lowering PG_VERSION or changing unrelated naming options may hide the symptom, but they do not address the underlying FK generation logic.
- Dominant language
- Perl
- Stars
- 1.2k
- Forks
- 378
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from darold/ora2pg
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 58/100
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
-
upgrade Open
Difficulty 1/5 Under an hour Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
1.severity: security
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
api7/lua-resty-saml#63 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100