Skip to main content

ratel diff

Generate migration diffs by comparing your models against the current database state.

Usage

ratel diff [flags]

Flags

FlagShortDescription
--sql-sSQL schema file to compare against
--package-pGo package path(s) containing models (comma-separated or repeated)
--tables-tTable variable names
--discover-dAuto-discover tables
--dirMigration directory (default: ./migrations)
--name-nMigration name (default: migration)
--pg_versionPostgreSQL version (default: 18)
--engine-eMigration engine: atlas or ratel (default: atlas)

Migration Engines

atlas (default)

Uses Atlas OSS for diffing. Supports tables, columns, indexes, foreign keys, and check constraints.

ratel

Native engine with full PostgreSQL support. Use this when you need Row Level Security, triggers, functions, or extensions — features that require Atlas Pro (paid license).

ratel diff --engine ratel -p github.com/myapp/models --discover \
-d ./migrations -n add_rls_policies

Examples

# From Go models (single package)
ratel diff -p github.com/myapp/models --discover \
-d ./migrations -n add_profiles

# From multiple packages
ratel diff -p github.com/myapp/auth,github.com/myapp/store \
--discover -d ./migrations -n init

# From SQL file
ratel diff -s schema.sql -d ./migrations -n initial

# With RLS/triggers support
ratel diff --engine ratel -p github.com/myapp/models --discover \
-d ./migrations -n add_security

How It Works

  1. Generates the desired schema from your models (or reads from SQL file)
  2. Compares against the current database state (from applied migrations)
  3. Produces a migration file with the required changes
  4. Updates atlas.sum checksum for compatibility

The generated migration file is placed in the --dir directory with a timestamp prefix.