🚀 Quick Start

Send two SQL schemas to the endpoint and get back a full diff, migration SQL, and breaking change analysis. API access requires a SchemaLens Pro license key.

POST /api/diff
curl -X POST https://schemalens.tech/api/diff \
  -H "Content-Type: application/json" \
  -H "X-License-Key: SL-XXXX-XXXX-XXXX-XXXX" \
  -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, oracle
formatstringNojson (default) or markdown
licenseKeystringYesSchemaLens Pro license key. Can also be sent via X-License-Key header.

📤 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" \
  -H "X-License-Key: SL-XXXX-XXXX-XXXX-XXXX" \
  -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:

💬 Slack Webhooks

Send diff summaries directly to a Slack channel. Perfect for team notifications and CI/CD alerts.

POST /api/slack
ParameterTypeRequiredDescription
webhookUrlstringYesSlack Incoming Webhook URL (https://hooks.slack.com/services/...)
diffobjectYesDiff result from /api/diff.
migrationstringNoGenerated migration SQL to include in the message.
breakingChangesarrayNoBreaking changes array to highlight critical issues.
dialectstringNoSQL dialect for context.
curl -X POST https://schemalens.tech/api/slack \
  -H "Content-Type: application/json" \
  -d '{
    "webhookUrl": "https://hooks.slack.com/services/T00/B00/XXXX",
    "diff": { /* diff object */ },
    "migration": "ALTER TABLE ...",
    "breakingChanges": [],
    "dialect": "postgres"
  }'

Response:

{ "success": true, "message": "Sent to Slack successfully." }

🛠️ 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