Skip to content

Pre/post scripts

File location: schema/pre/<name>.sql

Run before schema migration, in alphabetical order. Use for data cleanup, temporary table setup, or anything that needs to happen before DDL.

-- schema/pre/001_cleanup.sql
DELETE FROM temp_data WHERE created_at < now() - interval '30 days';

File location: schema/post/<name>.sql

Run after schema migration, in alphabetical order. Use for view refreshes, data backfills, or cache warming.

-- schema/post/001_refresh_views.sql
REFRESH MATERIALIZED VIEW CONCURRENTLY user_stats;
Terminal window
npx @smplcty/schema-flow new pre --name cleanup
npx @smplcty/schema-flow new post --name refresh-views

Creates timestamped template files like schema/pre/20240115120000_cleanup.sql.

All files (YAML and SQL) are tracked by SHA-256 hash. A file is re-run only when its content changes. There is no distinction between one-shot and repeatable scripts — everything is hash-tracked uniformly.

PhaseWhen
Pre-scriptsPhase 1 (after internal schema setup, before extensions)
Post-scriptsPhase 16 (after seeds, last phase)