Automatically generate beautiful Entity Relationship Diagrams from your SQL files!
- π Instant ERD Generation - Run
mmerdin any directory with SQL files - π Smart Relationship Detection - Automatically finds foreign key relationships across multiple SQL files
- π High-Resolution Output - Generates crisp, scalable diagrams (PNG and SVG)
- π― Zero Configuration - Works out of the box with sensible defaults
- π Multi-File Support - Perfect for projects that organize tables in separate SQL files
- π¨ Mermaid Powered - Leverages Mermaid.js for beautiful, customizable diagrams
Running mmerd on a blog database with separate SQL files for users, posts, comments, and tags:
erDiagram
users ||--o{ posts : "writes"
users ||--o{ comments : "authors"
posts ||--o{ comments : "has"
posts ||--o{ post_tags : "tagged"
tags ||--o{ post_tags : "applied"
# Clone the repository
git clone https://github.com/yourusername/mmerd.git
cd mmerd
# Run the installer
./install.shThe installer will:
- β Check for Node.js and npm (required prerequisites)
- β Install mermaid-cli if not present
- β
Install mmerd and companion tools to
~/.local/bin - β
Add
~/.local/binto your PATH if needed
# Navigate to a directory with SQL files
cd /path/to/your/database/schemas
# Generate ERD
mmerd
# Output:
# β Created: database_erd.mermaid
# β Created: database_erd.png
# πΌοΈ Opens the diagram automatically!| Command | Description | Usage |
|---|---|---|
mmerd |
Generate ERD from SQL files in current directory | mmerd |
mmviz |
Convert .mermaid file to high-res PNG | mmviz diagram.mermaid |
mmsvg |
Convert .mermaid file to scalable SVG | mmsvg diagram.mermaid |
mmview |
Quick view any image file | mmview output.png |
- Scans all
.sqlfiles in the current directory - Parses CREATE TABLE statements to extract table structure
- Detects relationships through:
- Inline REFERENCES clauses
- FOREIGN KEY constraints
- ALTER TABLE ADD FOREIGN KEY statements
- Generates a Mermaid ERD with proper relationships
- Renders to high-resolution PNG (4x scale for clarity)
- Opens the diagram in your default image viewer
Perfect for:
- π Documentation - Auto-generate database diagrams for your docs
- π Code Reviews - Visualize schema changes in PRs
- π Learning - Understand database structures quickly
- ποΈ Design - Validate relationships before implementation
- π Debugging - Spot missing or incorrect foreign keys
mmerd/
βββ bin/
β βββ mmerd # Main ERD generator
β βββ mmviz # Mermaid to PNG converter
β βββ mmsvg # Mermaid to SVG converter
βββ examples/
β βββ users.sql # Sample schema files
β βββ posts.sql
β βββ comments.sql
β βββ tags.sql
βββ install.sh # Installation script
βββ uninstall.sh # Uninstallation script
βββ README.md # You are here!
- Node.js (v14 or higher)
- npm (comes with Node.js)
Don't have Node.js? Install it from:
- Ubuntu/Debian:
sudo apt-get install nodejs npm - macOS:
brew install node - Windows/Others: nodejs.org
mmerd works with standard SQL CREATE TABLE syntax:
-- Basic table
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL
);
-- Table with foreign key
CREATE TABLE posts (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
title VARCHAR(200) NOT NULL,
content TEXT
);Supported:
- β CREATE TABLE statements
- β Inline REFERENCES clauses
- β FOREIGN KEY constraints
- β ALTER TABLE ADD FOREIGN KEY
- β Multiple files with cross-file relationships
By default, mmerd creates:
database_erd.mermaid- Mermaid source filedatabase_erd.png- Rendered diagram
You can edit the .mermaid file and re-render:
# Edit the mermaid file
nano database_erd.mermaid
# Re-render to PNG
mmviz database_erd.mermaid
# Or render to SVG for infinite scaling
mmsvg database_erd.mermaidcd mmerd
./uninstall.shThis will:
- Remove mmerd scripts from
~/.local/bin - Optionally uninstall mermaid-cli
- Keep your Node.js installation intact
Contributions are welcome! Feel free to:
- π Report bugs
- π‘ Suggest features
- π§ Submit PRs
MIT License - feel free to use in your projects!
- Mermaid.js - The amazing diagramming library
- mermaid-cli - Command-line interface for Mermaid
# Create a temporary directory
mkdir temp_erd
# Copy only the SQL files you want
cp users.sql posts.sql temp_erd/
cd temp_erd
mmerd# Add to your project
mmerd
git add database_erd.mermaid
git commit -m "Update database ERD"# GitHub Actions example
- name: Generate ERD
run: |
npm install -g @mermaid-js/mermaid-cli
mmerd
mkdir -p docs/diagrams
mv database_erd.png docs/diagrams/mmerd: command not found
- Run
source ~/.bashrc(orsource ~/.zshrcfor zsh) - Ensure
~/.local/binis in your PATH
No SQL files found
- Ensure you're in a directory with
.sqlfiles - Check file extensions are
.sql(not.SQLor.sql.txt)
Diagram not opening automatically
- Linux: Install
xdg-utils - macOS: Should work automatically
- Windows: WSL may need additional configuration
Made with β€οΈ for developers who love clean database documentation