A command-line tool to convert between database schema formats. Supports DBML, JSON, PostgreSQL, MySQL, SQLite, MariaDB, MSSQL, and Mermaid ER diagrams.
drawdb-cli is designed to be easily integrated into your CI/CD pipelines (GitHub Actions, GitLab CI, Jenkins, etc.) to automate schema conversions and documentation generation.
Automatically convert your DBML schema to SQL and Mermaid diagrams on every push.
name: Schema Automation
on: [push]
jobs:
convert:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm install -g drawdb-cli
- name: Generate SQL
run: drawdb-cli convert schema.dbml --to postgres -o schema.sql
- name: Generate Diagram
run: drawdb-cli convert schema.dbml --to mermaid -o diagram.mmdThe CLI returns standard exit codes for automation:
0: Success1: Error (file not found, syntax error, invalid arguments)
npm install -g drawdb-cliOr for local development:
cd drawdb-cli
npm install
npm link# DBML to JSON
drawdb-cli convert schema.dbml -o diagram.json
# JSON to PostgreSQL
drawdb-cli convert diagram.json -o schema.pgsql --to postgres
# DBML to MySQL
drawdb-cli convert schema.dbml -o schema.sql --to mysql
# Generate Mermaid ER diagram
drawdb-cli convert schema.dbml -o diagram.mmd --to mermaid
# Explicit format specification
drawdb-cli convert input.txt --from dbml --to json -o output.json
# Pipe support (stdin/stdout)
cat schema.dbml | drawdb-cli convert - --from dbml --to json > output.json
echo "Table users { id integer [pk] }" | drawdb-cli convert - --from dbml --to postgresdrawdb-cli formats| Format | Import | Export | Extension | Notes |
|---|---|---|---|---|
| DBML | β | β | .dbml | Database Markup Language |
| JSON | β | β | .json | DrawDB internal format |
| PostgreSQL | β | β | .pgsql | Full SQL with ENUMS |
| MySQL | β | β | .sql, .mysql | AUTO_INCREMENT, ENUM |
| SQLite | β | β | .sqlite | Inline foreign keys |
| MariaDB | β | β | .mariadb | CREATE OR REPLACE |
| MSSQL | β | β | .mssql | IDENTITY, extended props |
| Mermaid | β | β | .mmd | ER diagram visualization |
| Feature | DBML | PostgreSQL | MySQL | SQLite | MariaDB | MSSQL | Mermaid |
|---|---|---|---|---|---|---|---|
| Tables | β | β | β | β | β | β | β |
| Columns | β | β | β | β | β | β | β |
| Primary Keys | β | β | β | β | β | β | β |
| Foreign Keys | β | β | β | β | β | β | β |
| Indexes | β | β | β | β | β | β | β |
| Enums | β | β | β | β | β | β | β |
| Comments | β | β | β | β | β | β | β |
| Default Values | β | β | β | β | β | β | β |
| Auto Increment | β | β | β | β | β | β | β |
The CLI could not detect the format from the file extension. Use the --from flag to specify it explicitly:
drawdb-cli convert input.txt --from dbml --to jsonThis error occurs when converting to DBML if there are duplicate relationships between tables. Check your source schema for redundant foreign keys.
Ensure your input file follows the standard syntax for that format. For SQL imports, the parser supports standard CREATE TABLE statements but might fail on complex database-specific procedural code (triggers, stored procedures).
import { convert, fromDBML, toDBML, fromPostgres, toPostgres } from 'drawdb-cli';
// Convert DBML to internal JSON diagram
const dbml = `Table users { id integer [pk] }`;
const diagram = fromDBML(dbml);
// Export to different formats
const postgres = toPostgres(diagram);
const dbmlOutput = toDBML(diagram);
// Generic convert function
const json = convert(dbml, 'dbml', 'json');
const mysql = convert(dbml, 'dbml', 'mysql');Usage: drawdb-cli [command] [options]
Commands:
convert <input> Convert between schema formats
formats List all supported formats
help [command] Display help for command
Convert Options:
-o, --output <file> Output file (default: stdout)
-f, --from <format> Source format (auto-detected from extension)
-t, --to <format> Target format (required if no output file)
-h, --help Display help
# PostgreSQL β MySQL
drawdb-cli convert schema.pgsql --from postgres --to mysql -o schema.sql
# MySQL β Mermaid (for documentation)
drawdb-cli convert schema.sql --from mysql --to mermaid -o diagram.mmd
# DBML β All SQL formats
for fmt in postgres mysql sqlite mariadb mssql; do
drawdb-cli convert schema.dbml --to $fmt -o "schema.$fmt"
done# Fetch and convert
curl -s https://example.com/schema.dbml | drawdb-cli convert - --from dbml --to postgres
# Convert and validate
drawdb-cli convert schema.dbml --to postgres | psql -d mydbMIT