DB Diagram

April 9, 2026 ยท View on GitHub

Design, edit, and explore database schemas visually in VS Code.

๐Ÿš€ Features

๐Ÿ“Š Diagram View

FeatureDescription
Live ConnectionConnects directly to MySQL databases
Schema VisualizationAutomatically renders all tables, columns, types, and PK/FK badges
3 Layout Modes๐Ÿ“Š Hierarchical, โ„๏ธ Snowflake, ๐Ÿ“ฆ Compact
Drag & DropMove tables freely
Pan & ZoomPan with mouse, zoom with scroll (20%โ€“300%)
Fit to ViewFit all tables to the screen with a single click
PNG ExportSave the diagram as PNG

โœ๏ธ Editing

FeatureDescription
Add TableCreate new tables with a visual form
Add ColumnRight-click โ†’ Add Column (type, nullable, default, position)
Add RelationshipVisual FK builder โ€” select from/to table and column
DeletionDelete Table / Column / FK via right-click menu
Raw SQLExecute any DDL command

๐Ÿ” Search & Filtering

FeatureDescription
Table SearchFilter by table name
Column SearchFilter by column name or type
Type FilterFilter by INT, VARCHAR, TEXT, JSON, etc.

๐Ÿ“ Notes & History

FeatureDescription
Table NotesAdd notes to each table, view on hover
Snapshot HistorySave and restore schema snapshots
Schema DiffCompare differences between two snapshots

๐Ÿ“ฆ Migration Export

FormatDescription
SQLALTER TABLE commands
PrismaPrisma Schema
TypeORMTypeORM Entities

๐Ÿ“‹ Requirements

  • VS Code 1.75+
  • MySQL 5.7+ or MariaDB 10.3+

๐Ÿš€ Quick Start

1. Installation

cd db-diagram-designer
npm install

2. Compilation

npm run compile
# or watch mode:
npm run watch

3. Running

Press F5 in VS Code to open the Extension Development Host.

4. Connection

Open the Command Palette (Cmd+Shift+P) and run:

DB Diagram: Connect to Database

Enter your connection details (5 steps: host โ†’ port โ†’ user โ†’ password โ†’ database).

5. Opening the Diagram

The diagram opens automatically after connecting. Alternatively:

DB Diagram: Open Diagram

๐Ÿ“– Usage

Toolbar

ButtonAction
๏ผ‹ TableOpens the table creation form
โŸท RelationOpens the FK relationship builder
โŠž QueryOpens the Query Builder
โŒจ SQLExecute DDL commands
๐Ÿ“ทExport as PNG
๐Ÿ“ฆMigration export
๐Ÿ•Snapshot history
โŠ•Schema Diff
โŠกFit to view
โ†ปRefresh schema

Layout Modes

ModeDescription
๐Ÿ“Š HierarchicalLevel-based arrangement based on FK relationships
โ„๏ธ SnowflakeMost connected table in the center, others around it
๐Ÿ“ฆ CompactTight grid layout, for tables with few relationships

Canvas Interactions

InteractionAction
Drag table headerMove the table
ScrollZoom in/out
Drag empty spacePan the canvas
Right-click โ†’ table headerTable actions menu
Right-click โ†’ columnColumn deletion option
Right-click โ†’ FK lineRelationship deletion option
Click tableSelect (border highlighted)
Hover on ๐Ÿ“ iconView note

๐Ÿ—๏ธ Architecture

db-diagram-designer/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ extension.ts              # Entry point, command registrations
โ”‚   โ”œโ”€โ”€ db/
โ”‚   โ”‚   โ”œโ”€โ”€ DatabaseManager.ts    # Database connection manager
โ”‚   โ”‚   โ”œโ”€โ”€ MySQLDatabase.ts      # MySQL implementation
โ”‚   โ”‚   โ”œโ”€โ”€ PostgreSQLDatabase.ts # PostgreSQL implementation
โ”‚   โ”‚   โ””โ”€โ”€ types.ts              # Type definitions
โ”‚   โ”œโ”€โ”€ panels/
โ”‚   โ”‚   โ”œโ”€โ”€ ConnectionPanel.ts    # Connection form webview
โ”‚   โ”‚   โ””โ”€โ”€ DiagramPanel.ts       # Diagram webview panel
โ”‚   โ”œโ”€โ”€ providers/
โ”‚   โ”‚   โ””โ”€โ”€ ConnectionsProvider.ts # Sidebar TreeView
โ”‚   โ””โ”€โ”€ managers/
โ”‚       โ”œโ”€โ”€ SnapshotManager.ts    # Snapshot management
โ”‚       โ”œโ”€โ”€ SchemaDiffManager.ts  # Schema comparison
โ”‚       โ””โ”€โ”€ MigrationManager.ts   # Migration code generation
โ”œโ”€โ”€ media/
โ”‚   โ””โ”€โ”€ diagram.html              # Diagram webview HTML
โ”œโ”€โ”€ package.json                  # Extension manifest
โ””โ”€โ”€ tsconfig.json

โšก Performance

This extension includes performance optimizations:

  • Lazy Loading: Renders only when needed
  • Collision Avoidance: Tables are placed with automatic collision prevention
  • Efficient Updates: Only changed parts are re-rendered
  • Memory Management: Memory is cleared when webview is disposed

๐Ÿ”’ Security

  • Passwords are never saved โ€” only host/port/user/database are stored in globalState
  • Webview uses CSP nonce โ€” inline scripts won't run without a nonce
  • All SQL identifiers are protected with backticks

๐Ÿ“ License

MIT