Skip to content

feat: add cross-database foreign key configuration#554

Merged
dosco merged 2 commits intodosco:masterfrom
amitdeshmukh:feat/cross-database-foreign-keys
Mar 12, 2026
Merged

feat: add cross-database foreign key configuration#554
dosco merged 2 commits intodosco:masterfrom
amitdeshmukh:feat/cross-database-foreign-keys

Conversation

@amitdeshmukh
Copy link
Contributor

Summary

  • Adds colon-separated database prefix syntax to related_to config for cross-database FK references (e.g. ats:employees.id)
  • Resolves FK targets against the correct database's schema metadata instead of only the local database
  • Creates shadow nodes in the schema graph for cross-database targets, enabling the existing RelDatabaseJoin runtime path

Details

Previously, configuring related_to: "ats.employees.id" on a table in ats_orders would fail because GraphJin parsed it as schema.table.column and looked it up in the local database only. The new syntax ats:employees.id unambiguously separates the database name from the schema/table/column path and resolves the target column against the correct database's DBInfo.

Backward compatible — values without : parse identically to the existing behavior.

Test plan

  • Unit tests for getFK parsing with all syntax variants (2-part, 3-part, cross-db 2-part, cross-db 3-part, invalid)
  • Unit test for cross-database FK resolution via addForeignKeys
  • Unit test for unknown database error handling
  • Unit test for same-database FK regression (no FKeyDatabase set)
  • Unit test for shadow node creation in schema graph with IsCrossDatabase() verification
  • All existing core unit tests pass
  • Postgres integration tests pass
  • MSSQL integration tests pass

🤖 Generated with Claude Code

amitdeshmukh and others added 2 commits March 11, 2026 19:00
Enable `related_to` config to reference tables in other databases using
colon-separated syntax (e.g. `ats:employees.id`). This bridges the gap
between GraphJin's existing cross-database join runtime and config-time
FK declaration, allowing relationships like `job_crew.employee_id` in
`ats_orders` to reference `employees.id` in `ats`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
NormalizeDatabases, finalizeDatabaseSchema, and ensureDiscoveredTablesInConfig
all mutate Config.Tables/Databases/Roles. When the same *Config is reused
across multiple NewGraphJin calls, these mutations accumulate and can cause
duplicate table entries or stale state. Deep-copy the mutable fields at init
time so the caller's original Config is never modified.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dosco dosco merged commit 8199343 into dosco:master Mar 12, 2026
2 checks passed
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.

2 participants