🚀 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.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
schemaA | string | Yes | The old (base) schema SQL. |
schemaB | string | Yes | The new (target) schema SQL. |
dialect | string | No | postgres (default), mysql, sqlite, mssql, oracle |
format | string | No | json (default) or markdown |
licenseKey | string | Yes | SchemaLens 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:
- critical DROP_TABLE — Table removal
- critical DROP_COLUMN — Column removal
- critical ADD_NOT_NULL_NO_DEFAULT — NOT NULL column added without default
- critical DROP_CONSTRAINT — PRIMARY KEY, UNIQUE, or CHECK constraint dropped
- warning NARROW_TYPE — Column type narrowed (e.g., VARCHAR(255) → VARCHAR(100))
- warning ADD_FK_NO_INDEX — Foreign key added without supporting index
💬 Slack Webhooks
Send diff summaries directly to a Slack channel. Perfect for team notifications and CI/CD alerts.
| Parameter | Type | Required | Description |
|---|---|---|---|
webhookUrl | string | Yes | Slack Incoming Webhook URL (https://hooks.slack.com/services/...) |
diff | object | Yes | Diff result from /api/diff. |
migration | string | No | Generated migration SQL to include in the message. |
breakingChanges | array | No | Breaking changes array to highlight critical issues. |
dialect | string | No | SQL 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
- CREATE TABLE (columns, constraints, indexes)
- CREATE INDEX / UNIQUE INDEX
- CREATE TYPE ... AS ENUM (PostgreSQL)
- CREATE TRIGGER (PostgreSQL)
- CREATE VIEW
🔒 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