Pipeline stages
Overview
Section titled “Overview”DISCOVER -> PARSE -> EXPAND -> INTROSPECT -> PLAN -> EXECUTE1. Discover
Section titled “1. Discover”Glob for YAML files in conventional subdirectories (tables/, enums/, functions/, views/, roles/, mixins/) and SQL files in pre/, post/.
Each file gets a SHA-256 hash for change detection.
2. Parse
Section titled “2. Parse”Read each YAML file into typed TypeScript objects. Validate required fields and apply defaults.
The parser auto-detects file type by content:
table:field -> TableSchemaname:+values:-> EnumSchemaname:+body:-> FunctionSchemaname:+query:-> ViewSchema or MaterializedViewSchemarole:-> RoleSchemaextensions:-> ExtensionsSchemamixin:-> MixinSchema
3. Expand
Section titled “3. Expand”Load mixin definitions and merge their contributions (columns, indexes, triggers, policies, grants, checks) into consuming table schemas. Substitute {table} placeholders with table names.
4. Introspect
Section titled “4. Introspect”Query pg_catalog and information_schema filtered to the target pgSchema to read current database state:
- Tables and columns (types, defaults, nullability, generated expressions)
- Indexes (columns, uniqueness, method, WHERE, INCLUDE, opclass)
- Constraints (checks, foreign keys, unique)
- Enums (values and order)
- Functions (body, args, return type, attributes)
- Views and materialized views (query)
- Roles (attributes, memberships)
- Grants, triggers, policies, comments
5. Plan
Section titled “5. Plan”Diff desired (YAML) state vs actual (DB) state. Produce an ordered list of typed Operation objects, each with:
type: the operation type (e.g.,create_table,add_column)objectName: what it operates onsql: the SQL to executephase: execution phase (determines order)concurrent: whether to run outside transaction
Destructive operations are separated into a blocked list unless allowDestructive is true.
6. Execute
Section titled “6. Execute”Run operations in phased order within transactions. See execution phases.