Skip to content

feat: Add ER diagram visualization for database schemas#1589

Open
jcjaskula-aws wants to merge 1 commit into
mtxr:devfrom
jcjaskula-aws:jcjaskula-aws/er-diagrams
Open

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

Conversation

@jcjaskula-aws
Copy link
Copy Markdown

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

- 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
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