Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

DBDiff

> 数据库
Open source

Compare MySQL, Postgres or SQLite databases & automatically create schema & data change scripts/migrations automatically for database version control. Supports

741 stars0 likes1 views
WebsiteGitHub

About

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.

Features

  • Compares two databases (local or remote) and generates SQL migrations automatically
  • Supports MySQL, PostgreSQL, and SQLite via --driver
  • Connect via DSN URLs (--server1-url, --server2-url, --db-url) — works with any connection string
  • Supabase-ready via --supabase one-flag shorthand (not required when using DSN URLs)
  • Diffs tables, views, materialized views, triggers, stored procedures/functions, enum types, composite types, domains, sequences, row level security policies, and data — with deterministic, predictable output
  • Up and down SQL generated in the same file
  • Built-in migration runner: migration:up, down, status, validate, repair, baseline
  • Works with Flyway, Liquibase, Laravel Migrations, and more
  • Ignore specific tables or fields via a YAML config file
  • Unicode / UTF-8 aware
  • Fast — tested on databases with millions of rows; schema diffs use a constant number of round-trips regardless of table count
  • Runs on Windows, Linux and macOS (command-line / Terminal)

Supported Databases

Other versions may work but are not actively tested. PRs to add official support are welcome.

MySQL

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

PostgreSQL

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

Higher-fidelity DDL with pg_dump

When 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:

sql
-- DBDiff migration
-- Version: 20260901000613
-- Generated: 2026-09-01 00:06:13
-- Renderer: pg_dump

Set 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.

SQLite

Use --driver=sqlite. The file path is passed as the database name:

bash
./dbdiff --driver=sqlite server1./path/to/source.db:server1./path/to/target.db

SQLite 3.x is supported (any version supported by the installed pdo_sqlite PHP extension).

Supabase

--supabase sets driver=pgsql and enables SSL automatically:

bash
./dbdiff --supabase --server1=user:[email protected]:5432 server1.mydb:server1.mydb

Row 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.

Compatible Database Variants

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.

MySQL-compatible — --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

PostgreSQL-compatible — --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 Branching

Neon's copy-on-write branching lets you diff any two branches directly:

bash
./dbdiff \
  --server1-url postgres://user:[email protected]/mydb \
  --server2-url postgres://user:[email protected]/mydb \
  --format=flyway --description=my_feature

Dolt (Git for Databases)

Dolt is a MySQL-compatible database with Git-style branching. Each branch is exposed as a separate database:

bash
./dbdiff server1.main:server1.feature_add_users

Installation

The 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.

Pre-built Binaries

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:

bash
chmod +x dbdiff-linux-x64
sudo mv dbdiff-linux-x64 /usr/local/bin/dbdiff
dbdiff --version

npm

bash
npm install -g @dbdiff/cli
dbdiff --version

The 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:

bash
npm install -g @dbdiff/cli --registry=https://npm.pkg.github.com

PHAR

Download dbdiff.phar from GitHub Releases. Requires PHP ≥ 8.1.

bash
chmod +x dbdiff.phar
sudo mv dbdiff.phar /usr/local/bin/dbdiff
dbdiff --version

To build a PHAR locally from source, see Building a PHAR.

Docker / Podman

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.

Pull and run (no build required)

Docker:

bash
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.mydb

Podman (drop-in replacement — commands are identical):

bash
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.mydb

Podman on Linux runs rootless by default — no daemon required. Install via your package manager: sudo apt install podman (Debian/Ubuntu) or brew install podman (macOS).

Image variants

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.

Build locally

bash
# 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.

Composer Source Install

bash
git clone https://github.com/DBDiff/DBDiff.git
cd DBDiff
composer install --optimize-autoloader

Or as a project dependency:

bash
composer require "dbdiff/dbdiff:@dev"

Or globally:

bash
composer global require "dbdiff/dbdiff:@dev"

After installing from source, continue with Setup.

Setup

_For source installs (git clone / Composer) only.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPmigrationmigrationsmysqlmysql-database

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库