Skip to content

Add PostgreSQL semantic graph support - #1

Draft
dhritcu wants to merge 4 commits into
mainfrom
codex/postgres-support
Draft

Add PostgreSQL semantic graph support#1
dhritcu wants to merge 4 commits into
mainfrom
codex/postgres-support

Conversation

@dhritcu

@dhritcu dhritcu commented Aug 1, 2026

Copy link
Copy Markdown
Owner

What changed

  • add PostgreSQL parsing and semantic extraction using the vendored gmr/tree-sitter-postgres SQL grammar and its companion PL/pgSQL grammar
  • preserve PostgreSQL quoted-name boundaries, case folding, object-class intent, search_path, transaction, savepoint, and temporary-relation semantics
  • preprocess psql commands, variables, and COPY FROM STDIN payloads without changing source offsets, and report recovered parse errors
  • extract static SQL and PL/pgSQL routine-body calls and table, type, and sequence references while honoring routine-local SET search_path
  • model schemas, tables, altered columns, views, routines, types and enum mutations, triggers, policies, indexes, sequences, extensions, constraints, partitions, inheritance, and LIKE relationships
  • synthesize migration-ordered table/view drop, re-create, rename, constraint-rename, enum, foreign-key, and schema-containment relationships
  • keep strict ambiguity handling while selecting the correct preceding declaration at lifecycle boundaries
  • surface related tables, foreign keys, triggers, routines, and renamed constraints in node trails
  • bump the extraction version so existing indexes are prompted to rebuild

Why

The initial SQL support could locate declarations, but a useful database graph must answer relational questions without inventing dependencies. Looking up a table should expose its foreign-key neighbors, triggers, routines, and migration history. PostgreSQL naming, local search_path, psql input, repeated historical definitions, drops, re-creations, and renames all need ordered handling for those trails to stay accurate.

Validation

  • npm run build
  • PostgreSQL suite: 12 files, 108 tests passed
  • GIT_CONFIG_GLOBAL=/dev/null npm test
    • 157 test files passed; 15 skipped
    • 2,645 tests passed; 175 skipped
  • fresh Eversa development index using /private/tmp/codegraph-source/dist/bin/codegraph.js from this branch:
    • 7,553 files, 80,000 nodes, 257,404 edges
    • 110 PostgreSQL files, 3,096 PostgreSQL nodes, zero PostgreSQL parse errors
    • 148 foreign-key facts projected into 133 live table-to-table edges
    • all 7 altered enum values attached to their effective enum definitions
    • public.users exposes its FK neighbors, 6 triggers, routine/view/index references, and constraint names
    • renamed public.tags keeps its public.apps FK under tags_app_slug_fkey and its incoming public.tag_assignments FK
    • full index: 8.8s internal index phase, 26.18s process wall time, 1.74 GB peak RSS
    • no-change sync: 0.78s wall time, 133 MB peak RSS
    • 320.4 MB graph database; extraction version 27; zero pending changes or references

Intentional limits

  • dynamic SQL assembled through PL/pgSQL EXECUTE is skipped; only statically identifiable routine-body SQL is linked
  • migration chronology is inferred lexically within a directory; separate migration directories remain independent streams
  • server catalog contents are not indexed, so implicit pg_catalog lookup and external Supabase/auth/storage objects can remain unresolved
  • historical declarations and enum labels remain queryable; explicit rename transitions and synthesized live relationships carry current-state meaning

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