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)
--include-extension-objectsInclude objects owned by extensions
--reverseGenerate rollback plan (reverse direction)
--zero-downtimeGenerate expand/contract phased migration plan
--validate <URL>Validate migration against a temporary database first
--manage-ownershipInclude ownership management (ALTER ... OWNER TO)
--no-manage-grantsDisable grant/revoke management
--exclude-grants-for-role <ROLE>Exclude grants for a specific role (repeatable)
--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 (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)
--include-extension-objectsInclude objects owned by extensions
--validate <URL>Validate migration against a temporary database first
--manage-ownershipInclude ownership management (ALTER ... OWNER TO)
--no-manage-grantsDisable grant/revoke management
--exclude-grants-for-role <ROLE>Exclude grants for a specific role (repeatable)
-v, --verboseLog each statement execution and result
--jsonJSON output

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 (repeatable)
-d, --database <URL>PostgreSQL connection string
--target-schemas <LIST>Comma-separated PostgreSQL schemas (default: public)
--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 (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)
--include-extension-objectsInclude objects owned by extensions
--jsonJSON output (includes SQL content and metadata)

Validate a schema against a live database for issues.

Terminal window
pgmold lint -s sql:schema.sql -d postgres://localhost/mydb
FlagDescription
-s, --schema <SOURCE>Schema source (repeatable)
-d, --database <URL>PostgreSQL connection string
--target-schemas <LIST>Comma-separated PostgreSQL schemas (default: public)
--manage-ownershipInclude ownership management (ALTER ... OWNER TO)
--no-manage-grantsDisable grant/revoke management
--exclude-grants-for-role <ROLE>Exclude grants for a specific role (repeatable)
--jsonJSON output

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.

FlagDescription
-s, --schema <SOURCE>Schema source (repeatable)
-d, --database <URL>PostgreSQL connection string
-m, --migrations <DIR>Directory for migration files
-n, --name <NAME>Migration name/description
--target-schemas <LIST>Comma-separated PostgreSQL schemas (default: public)
--manage-ownershipInclude ownership management (ALTER ... OWNER TO)
--no-manage-grantsDisable grant/revoke management
--exclude-grants-for-role <ROLE>Exclude grants for a specific role (repeatable)
--jsonJSON output

Describe available commands, object types, providers, and filters. Intended for agent introspection.

Terminal window
pgmold describe
pgmold describe plan
ArgumentDescription
[COMMAND]Optional command name to describe (e.g., plan, apply)

Always outputs JSON. No database connection required.

PrefixDescription
sql:<path>SQL file, directory, or glob pattern
drizzle:<path>Drizzle ORM config file
db:<url>Live PostgreSQL database

All commands that accept -d also accept a bare postgres://... URL without the db: prefix.

VariableDescription
PGMOLD_DATABASE_URLDefault value for -d on all commands that accept a database URL
PGMOLD_PRODSet to 1 to enable production mode (blocks table drops)