CLI Commands
pgmold plan
Section titled “pgmold plan”Generate a migration plan without applying it.
pgmold plan -s sql:schema.sql -d postgres://localhost/mydb| Flag | Description |
|---|---|
-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-objects | Include objects owned by extensions |
--reverse | Generate rollback plan (reverse direction) |
--zero-downtime | Generate expand/contract phased migration plan |
--validate <URL> | Validate migration against a temporary database first |
--manage-ownership | Include ownership management (ALTER ... OWNER TO) |
--no-manage-grants | Disable grant/revoke management |
--exclude-grants-for-role <ROLE> | Exclude grants for a specific role (repeatable) |
--json | JSON output |
pgmold apply
Section titled “pgmold apply”Apply migrations to the database.
pgmold apply -s sql:schema.sql -d postgres://localhost/mydb| Flag | Description |
|---|---|
-s, --schema <SOURCE> | Schema source (repeatable) |
-d, --database <URL> | PostgreSQL connection string |
--allow-destructive | Allow DROP and other destructive operations |
--dry-run | Preview 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-objects | Include objects owned by extensions |
--validate <URL> | Validate migration against a temporary database first |
--manage-ownership | Include ownership management (ALTER ... OWNER TO) |
--no-manage-grants | Disable grant/revoke management |
--exclude-grants-for-role <ROLE> | Exclude grants for a specific role (repeatable) |
-v, --verbose | Log each statement execution and result |
--json | JSON output |
pgmold diff
Section titled “pgmold diff”Compare two schema sources.
pgmold diff --from sql:old.sql --to sql:new.sql| Flag | Description |
|---|---|
--from <SOURCE> | Source schema |
--to <SOURCE> | Target schema |
--json | JSON output |
pgmold drift
Section titled “pgmold drift”Detect schema drift between SQL files and a live database.
pgmold drift -s sql:schema.sql -d postgres://localhost/mydb --jsonReturns exit code 1 if drift is detected.
| Flag | Description |
|---|---|
-s, --schema <SOURCE> | Schema source (repeatable) |
-d, --database <URL> | PostgreSQL connection string |
--target-schemas <LIST> | Comma-separated PostgreSQL schemas (default: public) |
--json | JSON output |
pgmold dump
Section titled “pgmold dump”Export a live database schema to SQL.
pgmold dump -d postgres://localhost/mydb -o schema.sql| Flag | Description |
|---|---|
-d, --database <URL> | PostgreSQL connection string |
-o, --output <PATH> | Output file or directory |
--split | Split 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-objects | Include objects owned by extensions |
--json | JSON output (includes SQL content and metadata) |
pgmold lint
Section titled “pgmold lint”Validate a schema against a live database for issues.
pgmold lint -s sql:schema.sql -d postgres://localhost/mydb| Flag | Description |
|---|---|
-s, --schema <SOURCE> | Schema source (repeatable) |
-d, --database <URL> | PostgreSQL connection string |
--target-schemas <LIST> | Comma-separated PostgreSQL schemas (default: public) |
--manage-ownership | Include ownership management (ALTER ... OWNER TO) |
--no-manage-grants | Disable grant/revoke management |
--exclude-grants-for-role <ROLE> | Exclude grants for a specific role (repeatable) |
--json | JSON output |
pgmold migrate
Section titled “pgmold migrate”Generate a numbered migration file.
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.
| Flag | Description |
|---|---|
-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-ownership | Include ownership management (ALTER ... OWNER TO) |
--no-manage-grants | Disable grant/revoke management |
--exclude-grants-for-role <ROLE> | Exclude grants for a specific role (repeatable) |
--json | JSON output |
pgmold describe
Section titled “pgmold describe”Describe available commands, object types, providers, and filters. Intended for agent introspection.
pgmold describepgmold describe plan| Argument | Description |
|---|---|
[COMMAND] | Optional command name to describe (e.g., plan, apply) |
Always outputs JSON. No database connection required.
Schema source prefixes
Section titled “Schema source prefixes”| Prefix | Description |
|---|---|
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.
Environment variables
Section titled “Environment variables”| Variable | Description |
|---|---|
PGMOLD_DATABASE_URL | Default value for -d on all commands that accept a database URL |
PGMOLD_PROD | Set to 1 to enable production mode (blocks table drops) |