🚀 Quick Start

Send two SQL schemas to the endpoint and get back a full diff, migration SQL, and breaking change analysis.

POST /api/diff
curl -X POST https://schemalens.tech/api/diff \
  -H "Content-Type: application/json" \
  -d '{
    "schemaA": "CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(255));",
    "schemaB": "CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(255), email VARCHAR(255));",
    "dialect": "postgres",
    "format": "json"
  }'

📋 Parameters

ParameterTypeRequiredDescription
schemaAstringYesThe old (base) schema SQL.
schemaBstringYesThe new (target) schema SQL.
dialectstringNopostgres (default), mysql, sqlite, mssql
formatstringNojson (default) or markdown

📤 Response (JSON)

{
  "diff": { /* full diff object */ },
  "migration": "ALTER TABLE \"users\" ADD \"email\" VARCHAR ( 255 );",
  "breakingChanges": [],
  "summary": {
    "tablesAdded": 0,
    "tablesRemoved": 0,
    "tablesModified": 1,
    "enumsAdded": 0,
    "enumsRemoved": 0,
    "triggersAdded": 0,
    "triggersRemoved": 0,
    "triggersModified": 0,
    "viewsAdded": 0,
    "viewsRemoved": 0,
    "viewsModified": 0,
    "breakingChangeCount": 0
  }
}

📝 Response (Markdown)

Set format: "markdown" to receive a full markdown diff report suitable for PR comments, Slack messages, or documentation.

curl -X POST https://schemalens.tech/api/diff \
  -H "Content-Type: application/json" \
  -d '{
    "schemaA": "...",
    "schemaB": "...",
    "dialect": "postgres",
    "format": "markdown"
  }'

Response:

{
  "markdown": "# Schema Diff Report\n\n**Dialect:** PostgreSQL..."
}

🔥 Breaking Change Detection

The API automatically detects dangerous schema changes and returns them in the breakingChanges array:

🛠️ Supported Objects

🔒 Privacy

The API is stateless. Schema data is processed in-memory and never stored. No API key is required for the free tier. Rate limits are enforced at the edge by Vercel.

💻 CLI Alternative

For local use or CI/CD pipelines, use the SchemaLens CLI — a zero-dependency Node.js script that runs offline.

node ci/schemalens-diff.js schemaA.sql schemaB.sql --dialect=postgres --format=json