Skip to main content

schema-diff

Detects and reports schema differences between the production and development databases without touching any data.

Usage

deepdiffdb schema-diff --config deepdiffdb.config.yaml

What It Checks

  • Added tables — tables that exist in dev but not in prod
  • Removed tables — tables that exist in prod but not in dev
  • Column changes — per-column: data type, nullability, default value, column order
  • New columns — columns added in dev that are absent in prod
  • Dropped columns — columns present in prod that are absent in dev
  • Index changes — added, removed, or modified indexes (unique/non-unique)
  • Foreign key changes — added or removed FK constraints

Tables listed in ignore.tables are excluded entirely.

Flags

FlagDescription
--configPath to the configuration file (default: deepdiffdb.config.yaml)
--verboseEnable debug-level logging
--log-levelMinimum log level: debug, info, warn, error (default: info)
--log-formatLog output format: text or json (default: text)
--log-fileWrite logs to this file in addition to stdout

Output Files

Both files are written to output.dir (default: ./diff-output).

FileDescription
schema_diff.jsonMachine-readable schema differences, suitable for programmatic processing or CI checks
schema_diff.txtHuman-readable schema diff report

Example

deepdiffdb schema-diff --config deepdiffdb.config.yaml --log-level warn

Example schema_diff.txt output:

Schema Diff Report
==================

Table: orders
MODIFIED column: status
prod: VARCHAR(20) NOT NULL DEFAULT 'pending'
dev : VARCHAR(50) NOT NULL DEFAULT 'new'

ADDED column: shipped_at
dev : TIMESTAMP NULL

Table: products
ADDED index: idx_products_category (non-unique)
columns: category_id

Table: invoices
STATUS: ADDED (exists in dev, missing in prod)

Summary: 1 table added, 2 tables modified, 0 tables removed

Exit Codes

CodeMeaning
0No schema drift detected
1Schema drift detected or an error occurred

The non-zero exit on drift makes schema-diff useful as a CI/CD gate to block deployments when databases have diverged.