Skip to content

graph

Generate Entity-Relationship Diagrams (ERD) in multiple formats.

Alias: gr (e.g., sql-splitter gr dump.sql -o schema.html)

  • Schema documentation - Generate visual diagrams for documentation or onboarding
  • Dependency analysis - Understand which tables depend on which before refactoring
  • Safe DROP planning - See what depends on a table before dropping it
  • Circular dependency detection - Find problematic FK cycles that complicate migrations
  • Impact assessment - Before modifying a table, see all tables that reference it

Use order if you need to reorder a dump for safe imports based on the dependency graph.

The graph command parses CREATE TABLE statements and foreign key definitions to build a dependency graph:

  • Nodes = Tables (with columns, types, and constraints)
  • Edges = Foreign key relationships (A → B means “A references B”)

The direction matters: if orders.user_id references users.id, the edge goes orders → users. This means you must create users before orders.

Terminal window
sql-splitter graph <INPUT> [OPTIONS]
Terminal window
# Interactive HTML with pan/zoom (great for exploration)
sql-splitter graph dump.sql -o schema.html
# Mermaid format (embeds in Markdown docs)
sql-splitter graph dump.sql -o schema.mmd --format mermaid
# Graphviz DOT (for custom rendering)
sql-splitter graph dump.sql -o schema.dot

For large schemas, focus on what matters:

Terminal window
# Show only user-related and order-related tables
sql-splitter graph dump.sql --tables "user*,order*" --exclude "log*"
# Focus on one table and its dependencies (what it references)
sql-splitter graph dump.sql --table orders --transitive
# Focus on one table and its dependents (what references it)
sql-splitter graph dump.sql --table users --reverse

Circular FKs complicate imports and migrations. Find them:

Terminal window
# Show only tables involved in cycles
sql-splitter graph dump.sql --cycles-only
Terminal window
# Full schema as JSON for tooling
sql-splitter graph dump.sql --json
# Pipe to jq for analysis
sql-splitter graph dump.sql --json | jq '.relationships | length'
FlagShortDescriptionDefault
--output-oOutput file (html, dot, mmd, json, png, svg, pdf)stdout
--formatOutput format: html, dot, mermaid, jsonauto
--dialect-dSQL dialectauto-detect
--layoutLayout direction: lr (horizontal), tb (vertical)lr
--tables-tInclude tables matching glob patternsall
--exclude-eExclude tables matching glob patternsnone
--tableFocus on a specific table-
--transitiveShow all dependencies of focused tablefalse
--reverseShow all tables that depend on focused tablefalse
--max-depthLimit traversal depthunlimited
--cycles-onlyOnly show tables in circular dependenciesfalse
--renderRender DOT to PNG/SVG/PDF using Graphvizfalse
--progress-pShow progress barfalse
--jsonOutput as JSONfalse

Interactive diagram with:

  • Dark/light theme toggle
  • Pan and zoom
  • Click to highlight relationships
  • Copy Mermaid button
schema.dot
digraph schema {
rankdir=LR;
users [label="users|id INT PK\lname VARCHAR\lemail VARCHAR\l"];
orders [label="orders|id INT PK\luser_id INT FK\l"];
orders -> users [label="user_id"];
}

Render with Graphviz:

Terminal window
sql-splitter graph dump.sql -o schema.dot
dot -Tpng schema.dot -o schema.png

Or use --render:

Terminal window
sql-splitter graph dump.sql -o schema.png --render
erDiagram
users {
INT id PK
VARCHAR name
VARCHAR email
}
orders {
INT id PK
INT user_id FK
}
orders }|--|| users : user_id

Full schema details:

{
"tables": [
{
"name": "users",
"columns": [...],
"primary_key": ["id"],
"foreign_keys": []
}
],
"relationships": [...],
"cycles": []
}
Terminal window
sql-splitter graph dump.sql --table orders --transitive

Shows orders and all tables it references (directly or indirectly).

Terminal window
sql-splitter graph dump.sql --table users --reverse

Shows users and all tables that reference it.

Large schemas produce cluttered diagrams. Focus your view:

Terminal window
# Limit to specific tables
sql-splitter graph dump.sql --tables "core_*" --exclude "*_log,*_audit"
# Focus on a single table's neighborhood
sql-splitter graph dump.sql --table orders --transitive --max-depth 2
# Use JSON and filter programmatically
sql-splitter graph dump.sql --json | jq '.tables | map(select(.foreign_keys | length > 0))'

Missing edges (FK relationships not shown)

Section titled “Missing edges (FK relationships not shown)”

Foreign keys must be explicitly defined in CREATE TABLE statements. Implicit FKs (application-level only) won’t appear.

Check if FKs are defined:

Terminal window
sql-splitter graph dump.sql --json | jq '.relationships'

Install Graphviz, then render manually or use --render:

Terminal window
# Install Graphviz
brew install graphviz # macOS
apt install graphviz # Ubuntu/Debian
# Render DOT to PNG
sql-splitter graph dump.sql -o schema.dot
dot -Tpng schema.dot -o schema.png
# Or use --render (requires Graphviz installed)
sql-splitter graph dump.sql -o schema.png --render

Remember: edges point from the referencing table to the referenced table. If orders.user_id → users.id, the edge goes orders → users (orders depends on users).