Compare MySQL, Postgres or SQLite databases & automatically create schema & data change scripts/migrations automatically for database version control. Supports
Compare MySQL, Postgres or SQLite databases & automatically create schema & data change scripts/migrations automatically for database version control. Supports
DBDiff is an automated database schema and data diff tool for MySQL, Postgres & SQLite. It compares two databases, local or remote, and produces a migration file of the differences automatically.
When used alongside a compatible database migration tool, it can help enable database version control within your team or enterprise.--driver--server1-url, --server2-url, --db-url) — works with any connection string--supabase one-flag shorthand (not required when using DSN URLs)migration:up, down, status, validate, repair, baselineOther versions may work but are not actively tested. PRs to add official support are welcome.
| Version | Status |
|---|---|
| MySQL 8.0.x | ✅ Supported |
| MySQL 8.4.x (LTS) | ✅ Supported |
| MySQL 9.3.x (Innovation) | ✅ Supported |
| MySQL 9.6.x (Innovation) | ✅ Supported |
Use --driver=pgsql (or driver: pgsql in your .dbdiff config).
| Version | Status |
|---|---|
| PostgreSQL 14.x | ✅ Supported |
| PostgreSQL 15.x | ✅ Supported |
| PostgreSQL 16.x (LTS) | ✅ Supported |
| PostgreSQL 17.x | ✅ Supported |
| PostgreSQL 18.x | ✅ Supported |
pg_dumpWhen pg_dump and pg_restore are on PATH and at least as new as the
server, DBDiff uses them to render CREATE TABLE and everything attached to
it — indexes, constraints, identity sequence options, collations, storage,
compression and comments. They are PostgreSQL's own tooling, maintained in
lockstep with the server, so the DDL is what the server itself would produce.
Measured against the 90-case corpus in
@akalforge/pg-conformance
by convergence — build the case, reproduce it, replay it, compare catalog
fingerprints:
| renderer | reproduces |
|---|---|
| built-in | 68 / 90 |
with pg_dump |
81 / 90 |
Measured on PostgreSQL 16. The figures move by a case or two with the server:
the built-in renderer reproduces 67 on PostgreSQL 18, where LIKE ... INCLUDING ALL copies the named NOT NULL constraints that release introduced. And
pg_dump only counts when it is at least as new as the server — an older one is
not used at all, so those runs score as built-in.
Nothing is required. pg_dump is not bundled — the released binaries are
static PHP and cannot carry it — so when it is absent, or older than the
server, DBDiff falls back to its built-in renderer and says why.
Partitioned tables always use the built-in renderer, whatever is installed, and
that is deliberate rather than a limitation of the integration. pg_dump writes
a partitioned parent's primary key as ALTER TABLE ONLY parent ADD CONSTRAINT,
which reaches the partitions existing at the moment it runs and no others —
correct in pg_dump's own output order, and silently wrong as soon as anything
reorders the statements, which a tool applying a migration grouped by object
kind reasonably does. The built-in renderer puts the key inside CREATE TABLE,
where the partitions inherit it however the statements are ordered. It costs one
case in the table above — an expression partition key — and buys DDL that does
not depend on being applied in the order it was written.
A migration produced this way records it, so two machines emitting different SQL is explainable from the file:
-- DBDiff migration
-- Version: 20260901000613
-- Generated: 2026-09-01 00:06:13
-- Renderer: pg_dumpSet DBDIFF_PG_DUMP_RENDERER=off to pin a run to the built-in renderer — useful
when you need byte-identical output across machines regardless of what is
installed. DBDIFF_PG_DUMP and DBDIFF_PG_RESTORE override the binary paths.
Use --driver=sqlite. The file path is passed as the database name:
./dbdiff --driver=sqlite server1./path/to/source.db:server1./path/to/target.dbSQLite 3.x is supported (any version supported by the installed pdo_sqlite PHP extension).
--supabase sets driver=pgsql and enables SSL automatically:
./dbdiff --supabase --server1=user:[email protected]:5432 server1.mydb:server1.mydbRow level security is diffed as a first-class object — policies and each table's
ENABLE/FORCE ROW LEVEL SECURITY flags — which matters here because RLS is how
Supabase enforces per-row access. A policy dropped or changed between two
environments shows up in the migration instead of passing silently.
DBDiff reads the public schema, so policies and objects Supabase keeps in
auth, storage and its other managed schemas are outside the diff. Those are
managed by Supabase itself rather than by your migrations.
The databases below work with DBDiff's existing drivers with no code changes. Unless otherwise noted, these have not been tested by the core team. PRs to add official support are welcome.
--driver=mysql (default)| Database | Notes |
|---|---|
| MariaDB 10.x / 11.x | MySQL wire protocol; minor DDL dialect differences |
| AWS Aurora MySQL | Standard MySQL protocol |
| PlanetScale | MySQL-compatible SaaS |
| Vitess / VTGate | MySQL wire protocol via VTGate |
| Percona XtraDB Cluster | MySQL-compatible; Galera replication metadata ignored |
| TiDB | MySQL-compatible; default port 4000 |
| Dolt | MySQL-compatible, version-controlled; CI-tested |
--driver=pgsql| Database | Notes |
|---|---|
| AWS Aurora PostgreSQL | Standard pgsql connection |
| AWS RDS PostgreSQL | Standard pgsql connection |
| Neon | Standard pgsql; supports branch diffing (see below) |
| AlloyDB (Google Cloud) | Google's Postgres-compatible offering |
| CockroachDB | Postgres wire protocol; some DDL differences |
| YugabyteDB | Postgres-compatible YSQL layer |
| Multigres | Transparent Postgres proxy; no changes needed |
| TimescaleDB | Postgres extension; hypertable DDL diffs natively |
| pgvector | vector(N) columns and HNSW/IVFFlat indexes diff natively |
Neon's copy-on-write branching lets you diff any two branches directly:
./dbdiff \
--server1-url postgres://user:[email protected]/mydb \
--server2-url postgres://user:[email protected]/mydb \
--format=flyway --description=my_featureDolt is a MySQL-compatible database with Git-style branching. Each branch is exposed as a separate database:
./dbdiff server1.main:server1.feature_add_usersThe quickest way to get started is to download a pre-built release directly from GitHub Releases — no PHP, Node, or Composer required:
| Method | Available on Releases? | Best for |
|---|---|---|
| Pre-built binary | ✅ Yes | Quickest start — zero dependencies |
| PHAR | ✅ Yes | Single portable file; requires PHP ≥ 8.1 |
| npm | ✅ Yes (via registry) | Node.js projects or CI pipelines |
| Docker / Podman | — | Isolated environments, CI, or no local PHP |
| Composer (source) | — | Contributing to DBDiff or PHP integration |
PHP requirement: Pre-built binaries, npm packages, and Docker/Podman images bundle PHP 8.3 — no system PHP needed. The PHAR and Composer installs require PHP ≥ 8.1 on your system.
Download from GitHub Releases. No PHP, Node, or Composer required.
| Platform | Asset |
|---|---|
| Linux x64 (glibc) | dbdiff-linux-x64 |
| Linux x64 (Alpine / musl) | dbdiff-linux-x64-musl |
| Linux arm64 (glibc) | dbdiff-linux-arm64 |
| Linux arm64 (Alpine / musl) | dbdiff-linux-arm64-musl |
| macOS Apple Silicon | dbdiff-darwin-arm64 |
| macOS Intel | dbdiff-darwin-x64 |
| Windows x64 | dbdiff-win32-x64.exe |
| Windows arm64 | dbdiff-win32-arm64.exe |
After downloading, make it executable (Linux/macOS) and optionally move it to your PATH:
chmod +x dbdiff-linux-x64
sudo mv dbdiff-linux-x64 /usr/local/bin/dbdiff
dbdiff --versionnpm install -g @dbdiff/cli
dbdiff --versionThe correct platform binary is selected automatically at install time. Supported: Linux x64/arm64 (glibc + musl), macOS x64/arm64, Windows x64/arm64.
Packages are also published to GitHub Packages as a mirror. If npmjs.org is unavailable:
npm install -g @dbdiff/cli --registry=https://npm.pkg.github.comDownload dbdiff.phar from GitHub Releases. Requires PHP ≥ 8.1.
chmod +x dbdiff.phar
sudo mv dbdiff.phar /usr/local/bin/dbdiff
dbdiff --versionTo build a PHAR locally from source, see Building a PHAR.
Pre-built multi-arch images (linux/amd64 + linux/arm64) are published to GHCR on every release. Both Docker and Podman are fully supported — use whichever is available on your system. No local PHP installation is required.
Docker:
docker pull ghcr.io/dbdiff/dbdiff
docker run --rm ghcr.io/dbdiff/dbdiff --version
docker run --rm ghcr.io/dbdiff/dbdiff --driver=mysql \
--server1=user:pass@host:3306 server1.mydb:server1.mydbPodman (drop-in replacement — commands are identical):
podman pull ghcr.io/dbdiff/dbdiff
podman run --rm ghcr.io/dbdiff/dbdiff --version
podman run --rm ghcr.io/dbdiff/dbdiff --driver=mysql \
--server1=user:pass@host:3306 server1.mydb:server1.mydbPodman on Linux runs rootless by default — no daemon required. Install via your package manager:
sudo apt install podman(Debian/Ubuntu) orbrew install podman(macOS).
| Tag pattern | Registry | Description |
|---|---|---|
latest, {version}, slim-{version} |
GHCR | Slim — PHAR + PHP Alpine (~120 MB). For production use / CI. |
full, full-{version} |
GHCR | Full — Composer source install (~600 MB). For development and cross-version testing. |
# Slim image (requires dist/dbdiff.phar — run `vendor/bin/box compile` first)
# Replace 'docker' with 'podman' if using Podman
docker build -f docker/Dockerfile.slim -t dbdiff:slim .
docker run --rm dbdiff:slim --version
# Full image (Composer install from source — no PHAR needed)
docker build -f docker/Dockerfile -t dbdiff:full .See DOCKER.md for cross-version testing, Podman setup, and start.sh flags.
git clone https://github.com/DBDiff/DBDiff.git
cd DBDiff
composer install --optimize-autoloaderOr as a project dependency:
composer require "dbdiff/dbdiff:@dev"Or globally:
composer global require "dbdiff/dbdiff:@dev"After installing from source, continue with Setup.
_For source installs (git clone / Composer) only.
No open issues yet, or sync has not completed.