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 bigint pk
email text unique
name text
created_at timestamptz

Target

users
id bigint pk
email varchar(255) unique
display_name text
created_at timestamptz
updated_at timestamptz

Generated SQL

ALTER TABLE users
  RENAME COLUMN name TO display_name;

ALTER TABLE users
  ADD COLUMN updated_at timestamptz;

Compare

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

The practical win is speed of review. 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.

Dry run by default

Review is the default posture, which makes it easier to trust the tool inside a delivery workflow.

Dialects

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

The tool is useful precisely because it does not flatten everything to one generic SQL dialect. It keeps the generated statements 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 modes:

- sql
- table
- json
- dry-run review first