Database Schema Diff

Compare two database schemas and generate migration-oriented change reports

Compare two database schemas to identify table, column, index, and foreign key changes.

Supported inputs

  • SQL DDL
  • JSON or YAML schema summaries

Outputs

  • Structured diff report
  • Migration SQL draft
  • Visualization-friendly graph data

Example Results

2 examples

Compare SQL DDL and draft a PostgreSQL migration

Show how a schema gains a new required column and index, then generate the matching migration SQL.

{
  "summary": {
    "tablesAdded": 0,
    "tablesRemoved": 0,
    "columnsAdded": 1,
    "columnsRemoved": 0,
    "columnsChanged": 0,
    "indexesChanged": 1,
    "foreignKeysChanged": 0,
    "totalChanges": 2
  },
  "migrationSQL": "ALTER TABLE users ADD COLUMN email TEXT NOT NULL;\nCREATE INDEX idx_users_email ON users (email);"
}
View input parameters
{ "sourceSchema": "CREATE TABLE users (\n id INT PRIMARY KEY,\n name TEXT\n);", "targetSchema": "CREATE TABLE users (\n id INT PRIMARY KEY,\n name TEXT,\n email TEXT NOT NULL\n);\nCREATE INDEX idx_users_email ON users (email);", "schemaFormat": "sql", "dialect": "postgresql" }

Diff JSON schemas with SQLite-style removal warnings

Compare JSON schema summaries where one table and one column are removed, including the SQLite rebuild note.

{
  "summary": {
    "tablesRemoved": 1,
    "columnsRemoved": 1
  },
  "migrationSQL": "DROP TABLE audit_logs;\n-- SQLite requires table rebuild to drop column users.email"
}
View input parameters
{ "sourceSchema": "{\n \"tables\": {\n \"users\": {\n \"columns\": {\n \"id\": {\n \"type\": \"INTEGER\",\n \"primaryKey\": true,\n \"nullable\": false\n },\n \"email\": {\n \"type\": \"TEXT\",\n \"nullable\": false\n }\n }\n },\n \"audit_logs\": {\n \"columns\": {\n \"id\": {\n \"type\": \"INTEGER\",\n \"primaryKey\": true,\n \"nullable\": false\n }\n }\n }\n }\n}", "targetSchema": "{\n \"tables\": {\n \"users\": {\n \"columns\": {\n \"id\": {\n \"type\": \"INTEGER\",\n \"primaryKey\": true,\n \"nullable\": false\n }\n }\n }\n }\n}", "schemaFormat": "json", "dialect": "sqlite" }

Key Facts

Category
Developer & Web
Input Types
textarea, select
Output Type
json
Sample Coverage
4
API Ready
Yes

Overview

Compare two database schemas to identify structural changes and generate migration scripts. This tool analyzes SQL DDL or JSON/YAML schema definitions to detect added or removed tables, columns, indexes, and foreign keys, then drafts the corresponding SQL migration statements for MySQL, PostgreSQL, or SQLite.

When to Use

  • Before deploying database changes to production to verify migration safety and completeness
  • When refactoring legacy schemas to track exactly which tables and columns are being modified
  • During code reviews to validate that proposed schema changes match the intended target structure

How It Works

  • Paste your current schema into the Source Schema field and the desired schema into the Target Schema field
  • Select the schema format (SQL DDL or JSON/YAML) and database dialect (MySQL, PostgreSQL, or SQLite)
  • The tool parses both schemas and compares tables, columns, indexes, and foreign key constraints
  • Review the structured diff report and copy the generated migration SQL draft to apply changes

Use Cases

Generate migration scripts when adding new tables or columns to an existing database
Audit schema drift between development and production environments
Document structural changes during database refactoring or deprecation projects

Examples

1. PostgreSQL Migration for New User Fields

Backend Developer
Background
Preparing a production deployment that adds email tracking to the users table with a performance index.
Problem
Need to ensure the ALTER TABLE syntax is correct and includes the new index without dropping existing data.
How to Use
Paste the current CREATE TABLE users DDL into Source Schema, paste the updated DDL with the email column and CREATE INDEX statement into Target Schema, then select PostgreSQL dialect.
Outcome
Receives the exact ALTER TABLE statement to add the NOT NULL email column and the CREATE INDEX command ready for migration.

2. SQLite Cleanup of Deprecated Schema Objects

Database Administrator
Background
Refactoring a mobile app database to remove an unused audit_logs table and deprecated email column from the users table.
Problem
SQLite lacks direct ALTER TABLE DROP COLUMN support, requiring complex table rebuilds that are easy to script incorrectly.
How to Use
Input the current JSON schema summary containing both tables into Source Schema, input the target JSON with only the cleaned users table into Target Schema, select JSON format and SQLite dialect.
Outcome
Gets the DROP TABLE statement for audit_logs and a specific warning that removing the email column requires a table rebuild in SQLite.

Try with Samples

sql

Related Hubs

FAQ

What schema formats are supported?

SQL DDL statements, JSON, or YAML schema summaries.

Which database dialects are supported?

MySQL, PostgreSQL, and SQLite, with auto-detection available.

Does it detect foreign key changes?

Yes, it identifies added, removed, or modified foreign key constraints in the diff report.

Can I use this for SQLite column removal?

Yes, but the tool will note that SQLite requires table rebuilds for column drops.

Is the generated migration SQL production-ready?

It provides a draft that should be reviewed and tested in a staging environment before production deployment.

API Documentation

Request Endpoint

POST /en/api/tools/database-schema-diff

Request Parameters

Parameter Name Type Required Description
sourceSchema textarea Yes -
targetSchema textarea Yes -
schemaFormat select No -
dialect select No -

Response Format

{
  "key": {...},
  "metadata": {
    "key": "value"
  },
  "error": "Error message (optional)",
  "message": "Notification message (optional)"
}
JSON Data: JSON Data

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-database-schema-diff": {
      "name": "database-schema-diff",
      "description": "Compare two database schemas and generate migration-oriented change reports",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=database-schema-diff",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]