Skip to content

Execution phases

Operations execute in strict dependency order. This ensures PostgreSQL dependencies are satisfied (extensions before enums, enums before tables, tables before indexes, etc.).

PhaseObject typeNotes
0Internal schemaCREATE SCHEMA IF NOT EXISTS _smplcty_schema_flow
0+PrechecksPre-migration assertions (abort if falsy)
1Pre-scriptsSQL in pre/, alphabetical order
2ExtensionsCREATE EXTENSION IF NOT EXISTS
3EnumsCREATE TYPE ... AS ENUM, ALTER TYPE ... ADD VALUE
4RolesCREATE ROLE, ALTER ROLE, GRANT membership
5FunctionsCREATE OR REPLACE FUNCTION
6TablesCREATE TABLE, ALTER TABLE (columns, checks, unique) — without FKs
7IndexesCreated outside transaction using CONCURRENTLY
8Foreign keysAdded as NOT VALID, then validated separately
9ViewsCREATE OR REPLACE VIEW
10Materialized viewsCREATE MATERIALIZED VIEW, REFRESH
11TriggersCREATE TRIGGER
12RLS policiesENABLE ROW LEVEL SECURITY, CREATE POLICY
13GrantsGRANT/REVOKE on tables, columns, sequences, functions, schemas
14CommentsCOMMENT ON for all object types
15SeedsINSERT ... ON CONFLICT
16Post-scriptsSQL in post/, alphabetical order
  • Phases 0-6 and 8-16 run within a transaction (atomic commit or rollback)
  • Phase 7 (indexes) runs outside the transaction because CREATE INDEX CONCURRENTLY cannot run inside a transaction
  • If any transactional phase fails, all changes in that transaction roll back

create_table, drop_table, add_column, alter_column, drop_column

add_index, add_unique_index, drop_index

add_check, add_check_not_valid, drop_check, add_foreign_key, add_foreign_key_not_valid, validate_constraint, drop_foreign_key, add_unique_constraint, drop_unique_constraint

create_enum, add_enum_value, remove_enum_value

create_function

create_trigger, drop_trigger

enable_rls, disable_rls, create_policy, drop_policy

create_view, drop_view, create_materialized_view, drop_materialized_view, refresh_materialized_view

create_extension, drop_extension

create_role, alter_role, grant_membership, grant_table, grant_column, revoke_table, revoke_column, grant_sequence, revoke_sequence, grant_function, revoke_function, grant_schema

expand_column, create_dual_write_trigger, backfill_column, contract_column, drop_dual_write_trigger

create_schema

set_comment, add_seed, run_precheck