Skip to content

feat: Add ER diagram visualization for database schemas#1589

Open
jcjaskula-aws wants to merge 2 commits into
mtxr:devfrom
jcjaskula-aws:jcjaskula-aws/er-diagrams
Open

feat: Add ER diagram visualization for database schemas#1589
jcjaskula-aws wants to merge 2 commits into
mtxr:devfrom
jcjaskula-aws:jcjaskula-aws/er-diagrams

Conversation

@jcjaskula-aws

Copy link
Copy Markdown
Contributor

ER Diagram Visualization for Database Schemas

This PR adds an interactive Entity-Relationship diagram feature to SQLTools. Right-click any schema node in the connection explorer and select "Show ER Diagram" to visualize tables, columns, and foreign key relationships.

Features

  • Interactive diagram built with React Flow — pan, zoom, and drag tables to rearrange
  • Column-level FK connections — relationship lines connect from the specific FK column to the referenced PK column
  • Dagre auto-layout — tables are positioned using a directed graph layout algorithm that minimizes edge crossings
  • Per-table color coding — each table gets a consistent color; its outgoing FK edges use the same color for easy tracing
  • Focus mode — click a table (or use the search field in the toolbar) to highlight it and its connected tables, dimming everything else. Press Escape or click the background to clear
  • Searchable table picker — type to filter tables in the toolbar, select to focus and pan to the table
  • VS Code theme integration — uses CSS variables so it adapts to any light or dark theme
  • Multi-driver support — foreign key queries implemented for PostgreSQL, MySQL, MSSQL, and SQLite

Bug fix

  • Fixed a pre-existing event listener leak in the PG driver where notice handlers accumulated on pooled clients across queries

Changes across packages

  • types — Added NSDatabase.IForeignKey interface, fetchForeignKeys query builder, getERDiagramData driver method
  • base-driver — Implemented getERDiagramData in AbstractDriver
  • driver.pg/mysql/mssql/sqlite — Added fetchForeignKeys SQL queries
  • driver.pg — Fixed notice listener leak in query method
  • language-server — Added GetERDiagramDataRequest handler, Connection.getERDiagramData delegation
  • plugins/connection-manager — New command, LSP contract, webview provider, and React Flow UI
  • extension — Registered command, context menu on schema nodes, webpack entry point for ERDiagram webview

How to test

  1. Connect to a PostgreSQL (or MySQL/MSSQL/SQLite) database
  2. Expand the connection → database → schemas in the sidebar
  3. Right-click a schema → "Show ER Diagram"
  4. Verify tables render with columns, PK/FK badges, and colored relationship lines
  5. Click a table to enter focus mode; use the search field to find tables
  6. Drag tables, pan, and zoom to verify interactivity

Notes

I meant to write something that would solve #1304 but it is still lacking editing. Totally fine if a solution based on erd-editor is preferred.


Thank you for your contribution! Before submitting this PR, please make sure:

  • Your code builds clean without any errors or warnings
  • You have made the needed changes to the docs
  • You have written a description of what is the purpose of this pull request above

@gjsjohnmurray

Copy link
Copy Markdown
Collaborator

@jcjaskula-aws thanks for this contribution. I allowed the workflows to run but they both failed. Please investigate.

@jcjaskula-aws jcjaskula-aws force-pushed the jcjaskula-aws/er-diagrams branch from 4a098fc to 80234d8 Compare June 4, 2026 15:05
@jcjaskula-aws

Copy link
Copy Markdown
Contributor Author

@jcjaskula-aws thanks for this contribution. I allowed the workflows to run but they both failed. Please investigate.

Pushed a commit for this:

The ER diagram feature introduced react-flow-renderer which transitively pulls in @types/d3-dispatch@3.0.6+. This version uses const type parameters, incompatible with TS 4.8. The fix pins @types/d3-dispatch to 3.0.5 (pre-const syntax), and adds skipLibCheck: true to the base-driver and formatter tsconfigs to suppress separate DOM type errors from other hoisted @types/d3-* packages that reference browser globals unavailable in the "lib": ["es6"] config.

Not sure I like this fix. The feature of this MR is nice but this is not something critical (like the other AWS IAM MR which would make my life much easier). I'd say that if you have time and are willing to test, you could pull/build and play. If you feel it is a good addition, we could work on the implementation and review. Right now, the code changes are significant and it would take some efforts from many people to get it merged.

@jcjaskula-aws jcjaskula-aws force-pushed the jcjaskula-aws/er-diagrams branch from 80234d8 to e9f4b0e Compare June 4, 2026 21:40
@gjsjohnmurray

Copy link
Copy Markdown
Collaborator

Please update from dev to get the #1602 fix onto this branch.

- Right-click a schema node → "Show ER Diagram" opens an interactive
  React Flow-based diagram showing tables, columns, PK/FK markers,
  and foreign key relationships with column-level connections
- Dagre layout engine for automatic positioning that minimizes
  edge crossings
- Per-table color coding with colored relationship edges
- Focus mode: click a table or use the search field to highlight
  it and its connected tables, dimming everything else
- Foreign key queries added for PostgreSQL, MySQL, MSSQL, and SQLite
- Fixed pre-existing PG driver notice listener leak
Pin @types/d3-dispatch to 3.0.5 to avoid const type parameter syntax
incompatible with TS 4.8. Add skipLibCheck to base-driver and formatter
tsconfigs to prevent DOM type errors from other hoisted @types/d3-*
packages introduced by react-flow-renderer.
@jcjaskula-aws jcjaskula-aws force-pushed the jcjaskula-aws/er-diagrams branch from bd542c4 to d40d7d7 Compare June 10, 2026 02:13
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