schemalens-cli
v1.0.1
Published
CLI for SchemaLens — compare SQL schemas and generate migrations
Downloads
261
Maintainers
Readme
schemalens-cli
CLI for SchemaLens — compare SQL schemas and generate migrations locally.
Zero-install schema diffing from your terminal. Parse two SQL files, get a semantic diff, and generate ALTER TABLE migration scripts in PostgreSQL, MySQL, SQLite, SQL Server, or Oracle dialects.
Install
npm install -g schemalens-cli
# or use npx (no install)
npx schemalens-cli diff old.sql new.sqlUsage
schemalens diff <old.sql> <new.sql> [options]Options
| Flag | Description |
|------|-------------|
| -d, --dialect <dialect> | SQL dialect: postgres (default), mysql, sqlite, mssql, oracle |
| -f, --format <format> | Output format: pretty (default), json, markdown, sql |
| -o, --output <file> | Write output to file instead of stdout |
| -h, --help | Show help |
| -v, --version | Show version |
Examples
Pretty-printed diff (default)
schemalens diff schema-v1.sql schema-v2.sql --dialect postgresJSON output (great for CI/CD)
schemalens diff schema-v1.sql schema-v2.sql --format jsonSQL migration script
schemalens diff schema-v1.sql schema-v2.sql --format sql --output migration.sqlMarkdown report
schemalens diff schema-v1.sql schema-v2.sql --format markdown --output report.mdRead from stdin
cat schema-v2.sql | schemalens diff schema-v1.sql - --dialect mysqlFail on breaking changes (CI mode)
export SCHEMALENS_STRICT=1
schemalens diff schema-v1.sql schema-v2.sql --format json
# exits with code 2 if breaking changes are detectedOutput Formats
- pretty — Colorized terminal output with summary, risk score, breaking changes, and migration preview.
- json — Machine-readable JSON with
diff,migration,breakingChanges,riskScore, andsummary. - sql — Ready-to-run
ALTER TABLE/CREATE TABLEscript. - markdown — Human-readable report for PR descriptions or documentation.
Supported SQL
CREATE TABLEwith columns, constraints (PK, FK, UNIQUE, CHECK), and indexesCREATE INDEX/CREATE UNIQUE INDEXCREATE TYPE ... AS ENUM(PostgreSQL)CREATE VIEWCREATE TRIGGERCREATE FUNCTION/CREATE PROCEDURE
Exit Codes
| Code | Meaning |
|------|---------|
| 0 | Success, no breaking changes |
| 1 | General error (invalid args, file not found, parse error) |
| 2 | Breaking changes detected (only with SCHEMALENS_STRICT=1) |
Related
- SchemaLens Web App — Visual diff viewer with shareable links
- SchemaLens API — REST API for programmatic diffs
- SchemaLens GitHub
License
MIT
