Skip to content

Commands

Run full migration pipeline: pre-scripts, schema migration, post-scripts.

Terminal window
npx @smplcty/schema-flow run --db postgresql://user:pass@localhost:5432/mydb

Run only pre-scripts (SQL files in schema/pre/).

Run only the schema migration phase (YAML diffing and DDL execution).

Run only post-scripts (SQL files in schema/post/).

Dry-run. Shows planned operations without executing. Equivalent to run --dry-run.

Default output shows one line per planned operation plus a Plan: N operations would execute summary. Use --verbose to inline the SQL under each operation, or --json for machine-readable output. Unchanged pre/post scripts (whose recorded hash matches) are reported as skipped, mirroring what run would actually do.

Terminal window
npx @smplcty/schema-flow plan --db postgresql://user:pass@localhost:5432/mydb
npx @smplcty/schema-flow plan --verbose
npx @smplcty/schema-flow plan --json

Execute the migration plan inside a transaction that is always rolled back. Verifies SQL validity without making changes.

Mark the current database state as baseline. Records all current schema files in the history table without running any migrations. Use when adopting schema-flow on an existing database.

Terminal window
npx @smplcty/schema-flow baseline --db postgresql://user:pass@localhost:5432/mydb

Compare YAML definitions to the live database. Reports differences without making changes.

Terminal window
npx @smplcty/schema-flow drift --db postgresql://user:pass@localhost:5432/mydb

Detect drift and generate + execute a migration plan to fix all differences. Destructive fixes require --allow-destructive.

Static analysis of the migration plan. Warns about dangerous patterns like direct SET NOT NULL, dropping columns, type narrowing, missing FK indexes.

Show migration status: number of applied files, pending changes, and history.

Introspect an existing database and generate YAML files.

Terminal window
npx @smplcty/schema-flow generate --db postgresql://user:pass@localhost:5432/mydb --output-dir ./schema
npx @smplcty/schema-flow generate --db postgresql://... --seeds users,roles # include seed data

Generate a standalone .sql migration file from the current plan.

Terminal window
npx @smplcty/schema-flow sql --output migration.sql --db postgresql://user:pass@localhost:5432/mydb

Output includes transaction grouping, CONCURRENTLY operations outside transactions, phase comments, and blocked operations as comments.

Generate a Mermaid ER diagram from YAML definitions.

Terminal window
npx @smplcty/schema-flow erd --output schema.mmd

Create the standard project directory structure.

Terminal window
npx @smplcty/schema-flow init --dir ./schema

Create timestamped templates.

Terminal window
npx @smplcty/schema-flow new pre --name cleanup
npx @smplcty/schema-flow new post --name refresh-views
npx @smplcty/schema-flow new mixin --name timestamps

Print the YAML format reference to stdout.

Rollback to the previous migration snapshot. See rollback.

Drain pending expand-column backfills out-of-band. Idempotent and resumable; safe to kill and restart, safe to background via nohup / systemd / k8s. Foreground; sequential by default.

Terminal window
npx @smplcty/schema-flow backfill # drain all pending
npx @smplcty/schema-flow backfill --table users # one table only
npx @smplcty/schema-flow backfill --column users.email_lower
npx @smplcty/schema-flow backfill --concurrency 4 # opt-in parallelism
Flag Description
--table <name> Only backfill columns belonging to this table
--column <tbl.col> Only backfill this specific column
--concurrency N Backfills to run in parallel (default: 1, sequential)

Complete the contract phase of an expand/contract migration. Drops the old column and dual-write trigger. Requires --allow-destructive.

Refuses by default unless every row satisfies new_col IS NOT DISTINCT FROM transform(old_col) — i.e. backfill is complete. The error reports the row count remaining.

Flag Description
--force Drop the old column even if rows still diverge
--i-understand-data-loss Required alongside --force (data-loss confirmation)

Show status of in-progress expand/contract migrations, including per-state rows remaining for expanded columns.

Show help text.

Show version number.