Repository navigation
fix(postgres): resolve cross-schema foreign key references - #1474
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Notes
Files Reviewed (15 files)
Reviewed by claude-sonnet-5.5 · Input: 248 · Output: 2.4K · Cached: 277.4K Review guidance: REVIEW.md from base branch |
debba
left a comment
There was a problem hiding this comment.
Thanks @wuzi, both for reporting #1473 and for fixing it! Putting the logic in a single tested helper, getReferencedSchema, and using it for both the Related Records lookup and "Open referenced table" keeps it tidy. I also appreciate that you documented ref_schema in PLUGIN_GUIDE.md, added the batch-path assertion in the Postgres integration test, and opened the matching plugin PR. Using activeTab?.schema ?? activeSchema for the Related Records panel fixes a second, quieter bug too. I ran the driver's FK queries against a PostgreSQL 16 database with cross-schema, composite and quoted-name FKs, and the referenced schema came back correctly in every case.
Since this is your first PR here: if you'd like to hang out with us, we'd be glad to see you on Discord: https://discord.com/invite/K2hmhfHRSt
Approving. Two small follow-ups:
NewRowModal.tsx(not touched here) still loads the FK dropdown options from the source schema withquoteTableRef(fk.ref_table, activeDriver, activeSchema)andschema: activeSchema, so adding a row to a table with a cross-schema FK hits the samerelation ... does not existerror. UsinggetReferencedSchema(fk, activeSchema)for both would close the last gap. Feel free to add it here if you have a minute.- Optional: the Related Records header shows the bare table name. When a table with the same name exists in the source schema, showing
ref_schema.only when it differs would make it clear which one you're looking at.
#1478 touches the same code, so I'll coordinate the two. I'll also do a manual pass in the app before merging.
|
thanks for the review, @debba! Tabularis has become my daily driver for databases, so I’m glad to be able to contribute a little bit. Sounds good, I will join the Discord and do the small follow-up changes. |
Fixes #1473.
On PostgreSQL, a foreign key into another schema (
billing.carry_forwards.organization_id → core.organizations.id) broke the Related Records panel withrelation "billing.organizations" does not exist, and "Open referenced table" openedbilling.organizations. The driver already selected the referenced schema but dropped it, so the frontend qualifiedref_tablewith the source table's schema.ForeignKeygains an optionalref_schema, filled by the built-in PostgreSQL driver inget_foreign_keysandget_all_foreign_keys_batch. The frontend resolves the referenced schema through one helper,getReferencedSchema(ref_schema, else the source schema), used by the Related Records query and by "Open referenced table". The panel now receives the tab's schema rather than the sidebar's, matching the schema its FK metadata was loaded with. MySQL and SQLite leave the field unset.Plugin behaviour:
ref_schemais optional and additive (#[serde(default)]) and documented inPLUGIN_GUIDE.md. Plugins that return it get the fix; plugins that don't keep today's behaviour of assuming the source schema. Navigation still passes a schema only whencapabilities.schemasis true. The PostgreSQL plugin gets the field in TabularisDB/tabularis-postgresql-plugin#190; without it, its three FK parity tests diverge from the built-in driver.Validation:
ref_schemafor the single and batch paths (replacing its TODO), and both FK golden files gain the field.POSTGRES_PLUGIN_BINset to the patched plugin: all FK parity tests pass. 22 unrelated parity tests (timing fields, column metadata) also fail against the released plugin on main.getReferencedSchemaand a cross-schemafetchReferencedRecordcase that passes a capabilities object; the touched suites and editor page tests pass (170).pnpm typecheck, eslint, prettier, rustfmt on touched files, andcargo check --no-default-featurespass.core.organizations.Not changed here (same root cause, separate follow-ups): DDL generation emits
REFERENCESwithout a schema, ER diagram edges match by table name only, and MySQL cross-database foreign keys.