DBDiff

Schema diff and migration SQL

Review the schema drift before you run the migration.

DBDiff compares two databases, highlights structural differences, and generates dialect-aware migration SQL for PostgreSQL, MySQL, and SQL Server from one CLI.

Source

users
id bigserial pk
email text not null
last_seen timestamptz

Target

users
id bigserial pk
email varchar(255) not null

legacy_sessions
id bigserial pk
token text

Generated SQL

ALTER TABLE users ADD COLUMN
  last_seen timestamp with time zone NULL;

ALTER TABLE users ALTER COLUMN email
  TYPE text USING (email::text);

DROP TABLE IF EXISTS legacy_sessions CASCADE;

Compare

One CLI for schema inspection, SQL generation, and safer review loops.

Review faster. Instead of flipping between different tools for inspection and migration output, DBDiff keeps the diff, the dialect, and the generated SQL in one flow.

Diff first

Compare two instances before you touch production and catch drift while it is still explainable.

Generate SQL

Produce migration scripts in SQL, JSON, or table output depending on where the result needs to go next.

Review, then apply

compare and migrate only read the databases. apply asks before it changes one, unless --force, and records each migration in a tracking table.

Dialects

PostgreSQL, MySQL, and SQL Server with dialect-aware DDL.

DBDiff does not flatten everything to one generic SQL dialect. Generated statements stay close to the actual target platform.

PostgreSQL

`ALTER COLUMN TYPE`, schema-aware introspection, and transaction-friendly flows.

MySQL

`MODIFY COLUMN` generation and MySQL-specific comparison behavior.

SQL Server

Cross-instance diffing with SQL Server connection support built into the same CLI.

Install

Short path to the first diff.

Go install is the cleanest starting point. After that, compare two schemas and inspect the generated SQL before you wire the tool into a wider migration process.

go install github.com/meru143/dbdiff@latest

dbdiff compare postgres://source postgres://target
dbdiff migrate -s postgres://source -t postgres://target -o migration.sql
Output formats:

- sql
- table
- json

apply asks [y/N] before it writes:
dbdiff apply migration.sql postgres://target