Skip to main content
The diff command compares your current database schema (JSON file from extract) with your desired schema (SQL files) and displays the differences. Use this to preview what changes will be made before generating migrations.

Usage

Flags

Examples

Basic Comparison

Docker

Output Format

The diff command outputs a summary of detected changes grouped by severity:

Change Severities

pgtofu classifies all detected changes by their potential impact:

SAFE

Low risk - Additions and non-destructive changes
  • Adding tables, columns, indexes
  • Adding constraints
  • Creating views and functions

POTENTIALLY_BREAKING

Medium risk - May affect queries or applications
  • Dropping unused indexes
  • Changing defaults
  • Renaming objects

BREAKING

High risk - May cause data loss or downtime
  • Dropping tables or columns
  • Dropping constraints
  • Removing functions used by applications

DATA_MIGRATION_REQUIRED

Requires intervention - Cannot be automated
  • Changing column types incompatibly
  • Adding NOT NULL to existing columns without defaults
  • Complex schema transformations

Change Types

pgtofu detects over 40 different types of schema changes:

Type Compatibility

When comparing column types, pgtofu understands safe type widening:

Safe Widening (No Data Loss)

Incompatible Changes (Data Migration Required)

Desired Schema Format

The desired schema can be a single SQL file or a directory structure:

Single File

schema
tables
users.sql
orders.sql
pgtofu automatically discovers and parses all .sql files in the directory tree.
Organize SQL files by type for maintainability. pgtofu resolves dependencies automatically regardless of file organization.

Troubleshooting

Ensure your SQL files use the same schema names as the database. By default, PostgreSQL uses the public schema.
Check that your SQL syntax is valid. pgtofu supports standard PostgreSQL syntax including:
  • Dollar-quoted strings
  • Quoted identifiers
  • Complex expressions
View normalization may detect changes due to formatting differences. Use --preview with generate to see exact SQL.

See Also