Skip to content

feat(inference): suggest implicit foreign-key relationships#444

Open
seonghobae wants to merge 2 commits into
adhesive-piperfrom
feat/relationship-inference
Open

feat(inference): suggest implicit foreign-key relationships#444
seonghobae wants to merge 2 commits into
adhesive-piperfrom
feat/relationship-inference

Conversation

@seonghobae

Copy link
Copy Markdown
Collaborator

Stacked on adhesive-piper (PR #440). Implements P1 "relationship inference" from docs/valuation-gap-analysis.md.

Reverse-engineering undeclared relationships

GET /api/snapshots/{uuid}/inferred-relationships proposes implicit foreign keys that a database never declared — the core reason to use a schema-intelligence tool on legacy/analytics schemas over a generic ERD drawer.

Heuristic (high-precision, few false positives): a <X>_id column → a same-schema table X/Xs that has a PK; excludes already-declared FKs and a table's own PK (no self-loop). confidence: high when the column type matches the referenced key, else medium, each with a reason.

Pure/dialect-agnostic (app/spec/relationship_inference.py), IDOR-safe endpoint.

Verification

backend pytest 264 passed (+6). TDD caught a real self-PK false positive before merge.

Next (stacked): frontend surfacing — suggested relationships as dashed edges with one-click "add to diagram".

🤖 Generated with Claude Code

seonghobae and others added 2 commits July 5, 2026 23:50
infer_relationships(snapshot) proposes undeclared FKs for reverse-engineering DBs that never declared them: a '<X>_id' column -> a same-schema table X/Xs with a PK, excluding already-declared FKs and a table's own PK (no self-loop). Confidence high when column type matches the referenced key, else medium. Endpoint GET /api/snapshots/{uuid}/inferred-relationships (IDOR-safe). Pure/dialect-agnostic; +6 tests (TDD caught a self-PK false positive). Backend suite 264.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AxU2xaupAjp912oDNFuWyd
Same one-line union-attr fix as on adhesive-piper; makes backend CI (mypy) green on this stacked branch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AxU2xaupAjp912oDNFuWyd
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