Repository navigation
fix(postgres): preserve composite foreign key column order - #1002
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bc3969cd04
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| WHEN 'n' THEN 'SET NULL' | ||
| WHEN 'd' THEN 'SET DEFAULT' | ||
| END AS on_update | ||
| FROM pg_constraint AS constraint_row |
There was a problem hiding this comment.
Filter catalog constraints to tables visible to the role
When the connection role can access only part of a selected schema, pg_constraint and pg_attribute are still readable for the other tables, while generateTablesAndFields gets only privilege-visible rows from information_schema.columns. This therefore appends refs whose endpoint tables were not exported; importer.generateDbml rejects such an endpoint as a missing table, so db2dbml can stop producing output for least-privilege connections. Preserve the former information-schema privilege predicate or filter refs to exported tables.
Useful? React with 👍 / 👎.
| ON target_column.attrelid = target_table.oid | ||
| AND target_column.attnum = key_column.target_attnum | ||
| WHERE constraint_row.contype = 'f' | ||
| AND source_ns.nspname NOT IN ('pg_catalog', 'information_schema') |
There was a problem hiding this comment.
Exclude foreign keys from other sessions' temp schemas
When a fetch is run without schemas=... while another session has temporary tables with a foreign key, those constraints are present in pg_constraint under pg_temp_*, and this namespace check does not remove them. The information-schema views still used for tables and fields omit other sessions' temp schemas, so the returned ref points at tables absent from the result and downstream DBML generation fails or depends on unrelated session state. Add NOT pg_is_other_temp_schema(source_ns.oid) to retain the prior behavior.
Useful? React with 👍 / 👎.
|
Thank you for your contribution! |
Summary
PostgreSQL foreign-key metadata now keeps referencing and referenced columns paired in the constraint's declared order.
Issue
Closes #991
Lasting Changes (Technical)
Checklist
Evidence
master: the referenced columns came back as["alpha", "zeta"]instead of the declared["zeta", "alpha"].Merge Danger
Door: Two-way.
Blast Radius: PostgreSQL connector.