Skip to content

yaxit24/drawdb-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DrawDB CLI

A command-line tool to convert between database schema formats. Supports DBML, JSON, PostgreSQL, MySQL, SQLite, MariaDB, MSSQL, and Mermaid ER diagrams.

πŸ€– CI/CD & Automation

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.

Example: GitHub Actions

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

Exit Codes

The CLI returns standard exit codes for automation:

  • 0: Success
  • 1: Error (file not found, syntax error, invalid arguments)

🀝 Contributing

Installation

npm install -g drawdb-cli

Or for local development:

cd drawdb-cli
npm install
npm link

Usage

Convert between formats

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

List supported formats

drawdb-cli formats

Supported 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 Support Matrix

Feature DBML PostgreSQL MySQL SQLite MariaDB MSSQL Mermaid
Tables βœ… βœ… βœ… βœ… βœ… βœ… βœ…
Columns βœ… βœ… βœ… βœ… βœ… βœ… βœ…
Primary Keys βœ… βœ… βœ… βœ… βœ… βœ… βœ…
Foreign Keys βœ… βœ… βœ… βœ… βœ… βœ… βœ…
Indexes βœ… βœ… βœ… βœ… βœ… βœ… ❌
Enums βœ… βœ… βœ… ❌ βœ… ❌ ❌
Comments βœ… βœ… βœ… βœ… βœ… βœ… ❌
Default Values βœ… βœ… βœ… βœ… βœ… βœ… ❌
Auto Increment βœ… βœ… βœ… ❌ βœ… βœ… ❌

Troubleshooting

"Unsupported source format"

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 json

"References with same endpoints exist"

This error occurs when converting to DBML if there are duplicate relationships between tables. Check your source schema for redundant foreign keys.

"SyntaxError" during import

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

Programmatic Usage

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');

CLI Reference

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

Examples

Cross-format conversions

# 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

Pipeline integration

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

License

MIT

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published