Skip to content

CLI Commands

Generate a migration plan without applying it.

Terminal window
pgmold plan -s sql:schema.sql -d postgres://localhost/mydb
FlagDescription
-s, --schema <SOURCE>Schema source (repeatable). Prefix: sql: or drizzle:
-d, --database <URL>PostgreSQL connection string
--target-schemas <LIST>Comma-separated PostgreSQL schemas (default: public)
--include <PATTERN>Include objects matching glob pattern (repeatable)
--exclude <PATTERN>Exclude objects matching glob pattern (repeatable)
--include-types <TYPES>Include only these object types (comma-separated)
--exclude-types <TYPES>Exclude these object types (comma-separated)
--reverseGenerate rollback plan (reverse direction)
--jsonJSON output

Apply migrations to the database.

Terminal window
pgmold apply -s sql:schema.sql -d postgres://localhost/mydb
FlagDescription
-s, --schema <SOURCE>Schema source (repeatable)
-d, --database <URL>PostgreSQL connection string
--allow-destructiveAllow DROP and other destructive operations
--dry-runPreview SQL without executing
--target-schemas <LIST>Comma-separated PostgreSQL schemas
--include/--excludeSame as plan
--include-types/--exclude-typesSame as plan

Compare two schema sources.

Terminal window
pgmold diff --from sql:old.sql --to sql:new.sql
FlagDescription
--from <SOURCE>Source schema
--to <SOURCE>Target schema
--jsonJSON output

Detect schema drift between SQL files and a live database.

Terminal window
pgmold drift -s sql:schema.sql -d postgres://localhost/mydb --json

Returns exit code 1 if drift is detected.

FlagDescription
-s, --schema <SOURCE>Schema source
-d, --database <URL>PostgreSQL connection string
--target-schemas <LIST>Comma-separated PostgreSQL schemas
--jsonJSON output

Export a live database schema to SQL.

Terminal window
pgmold dump -d postgres://localhost/mydb -o schema.sql
FlagDescription
-d, --database <URL>PostgreSQL connection string
-o, --output <PATH>Output file or directory
--splitSplit into separate files by object type
--target-schemas <LIST>Comma-separated PostgreSQL schemas
--include-extension-objectsInclude objects owned by extensions

Validate a schema file for issues.

Terminal window
pgmold lint -s sql:schema.sql

Generate a numbered migration file.

Terminal window
pgmold migrate \
-s sql:schema/ \
-d postgres://localhost/mydb \
--migrations ./migrations \
--name "add_email_column"

Auto-detects the next migration number in the output directory.

PrefixDescription
sql:<path>SQL file, directory, or glob pattern
drizzle:<path>Drizzle ORM config file
db:<url>Live PostgreSQL database
VariableDescription
PGMOLD_PRODSet to 1 to enable production mode (blocks table drops)