Skip to content

fix(plugins): populate referenced schema for SQL Server and Oracle foreign keys#1760

Merged
datlechin merged 2 commits into
mainfrom
fix/mssql-oracle-fk-export-schema
Jun 23, 2026
Merged

fix(plugins): populate referenced schema for SQL Server and Oracle foreign keys#1760
datlechin merged 2 commits into
mainfrom
fix/mssql-oracle-fk-export-schema

Conversation

@datlechin

Copy link
Copy Markdown
Member

Problem

Following a foreign key (FK navigation in the data grid, FK preview) into a table that lives in a different schema opened the wrong table or failed, on SQL Server and Oracle. Found while reviewing #1754.

Root cause

The app already plumbs a referenced schema end to end: PluginForeignKeyInfo.referencedSchema exists, and PluginDriverAdapter maps it into the app's ForeignKeyInfo, which FK navigation reads. But the MSSQL and Oracle FK introspection queries never selected the referenced table's owner/schema, so referencedSchema was always nil. FK navigation then fell back to the current schema and qualified against the wrong table.

Fix

  • MSSQL: the FK queries now select sr.name AS ref_schema (joining sys.schemas on the referenced table's schema_id). The single-table path was a duplicate of the unused, tested MSSQLSchemaQueries.foreignKeys, so it now calls that shared query and parseForeignKeyRow instead of inline SQL. MSSQLForeignKeyRow and parseForeignKeyRow carry referencedSchema.
  • Oracle: the FK queries now select rc.OWNER AS REF_SCHEMA and map it into referencedSchema.

PluginForeignKeyInfo.referencedSchema already exists with a defaulted init parameter, so this is additive with no PluginKit ABI change.

Tests

TableProMSSQLCoreTests: the FK query selects ref_schema, and parseForeignKeyRow extracts referencedSchema (and stays nil when the column is absent). 20 pass.

Shipping

MSSQL and Oracle are registry-only plugins, so this reaches users after re-releasing both plugins.

Not included: export

The export path (ExportDataSourceAdapter) also drops schema for non-default-schema tables, but the fix is a separate, larger change: PluginExportTable (a PluginKit transfer type) and the PluginExportDataSource protocol methods carry only databaseName, no per-table schema, and the adapter is already inconsistent (it uses currentSchema for column/FK fetch but databaseName for the data query). Threading a real schema through export touches the transfer-type ABI and every export plugin, so it deserves its own scoped change.

Relates to #1754

https://claude.ai/code/session_0198faM6VCrViRU4XwRoS1DC

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: efa33538cc

ℹ️ 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".

referencedTable: refTable,
referencedColumn: refColumn
referencedColumn: refColumn,
referencedSchema: row[safe: 4] ?? nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pass the parsed schema to mobile FK results

Because this shared parser is also used by TableProMobile/TableProMobile/Drivers/MSSQLDriver.swift, and that call still constructs ForeignKeyInfo without forwarding $0.referencedSchema, SQL Server mobile FK navigation continues to receive a nil schema even though this query now returns it. Please thread the parsed schema through that mapping too; otherwise the cross-schema FK fix only applies to the plugin path.

Useful? React with 👍 / 👎.

Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
@datlechin datlechin merged commit e061b29 into main Jun 23, 2026
3 checks passed
@datlechin datlechin deleted the fix/mssql-oracle-fk-export-schema branch June 23, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant