Migration Sequencing V1
Intent
Section titled “Intent”Define a deterministic migration sequence for implementing the V1 relational blueprint with minimal risk and clear rollback boundaries.
Sequencing Principles
Section titled “Sequencing Principles”-
Identity first Person and identity bindings are prerequisites for nearly all domain rows.
-
Structure before activity Learning structure and memberships must exist before attempts and competency evidence.
-
Evidence before derived state Append-oriented evidence tables should be introduced before derived summary/state tables.
-
Exportability is not optional Portable history coverage is built in from first assessment rollout.
-
Sync columns early
updated_at_us, operation-link metadata, and deterministic apply-sequence columns should be available before client sync mutation traffic scales.
Phase Plan
Section titled “Phase Plan”Phase 0: Foundations and Enums
Section titled “Phase 0: Foundations and Enums”Create shared enums/domains and helper primitives:
- Lifecycle statuses (offering, membership, attempt, qualification)
- Scope and role enums
- Competency state enums
Verification:
- Enum values match architecture docs
- No duplicate semantic enums across table groups
Phase 1: Identity and Organization
Section titled “Phase 1: Identity and Organization”Create:
personperson_profileorganizationidentity_bindingorganization_affiliationperson_role_grant
Verification:
- External identity uniqueness constraints hold
- Temporal checks enforce valid windows
Phase 2: Learning Structure and Membership
Section titled “Phase 2: Learning Structure and Membership”Create:
learning_containerofferingoffering_membershiplearning_unitunit_release_rule
Verification:
- Unified membership uniqueness works for multi-role participation
- Offering and unit sequencing indexes satisfy expected query patterns
Phase 3: Assessment and Feedback
Section titled “Phase 3: Assessment and Feedback”Create:
assessment_definitionassessment_attemptassessment_scorefeedback_entrysubmission_artifact
Verification:
- Attempt uniqueness per person and assessment
- Feedback history is append-safe and queryable by attempt timeline
- Score provenance fields are non-null where required
Phase 4: Competency Framework
Section titled “Phase 4: Competency Framework”Create:
competency_frameworkcompetency_framework_versioncompetency_nodecompetency_node_edgecompetency_alignmentperson_competency_evidenceperson_competency_state
Verification:
- Framework version immutability controls are in place
- Evidence-to-state derivation can be executed deterministically
- Alignment temporal windows prevent historical rewrite ambiguity
Phase 5: Qualification and Portability
Section titled “Phase 5: Qualification and Portability”Create:
qualification_definitionqualification_awardprogress_snapshotactivity_eventchange_audit_entryexport_import_batch
Verification:
- Default export query includes full attempt and feedback history
- Audit entries can link mutations to source operation IDs
Phase 6: Sync Operation Linkage
Section titled “Phase 6: Sync Operation Linkage”Add or finalize:
last_operation_id(or validated equivalent) on mutable sync tableslast_apply_sequence(or equivalent deterministic ordering cursor) on mutable sync tables- Source operation propagation into
activity_eventandchange_audit_entry
Verification:
- Every client-submitted mutation has trace link to pgxsinkit operation log
- Admin/import/batch/system writes targeting syncable tables are validated through the same batch ingress and operation log
- LWW apply order can be reconstructed from deterministic apply sequence
Rollback and Safety Gates
Section titled “Rollback and Safety Gates”For each phase:
- Pre-migration snapshot and integrity baseline query set
- Apply migration
- Run integrity verification queries
- Run contract tests and sync smoke tests
- Promote only if checks pass
If checks fail:
- Use phase-local rollback scripts where feasible
- Otherwise execute documented compensation migration
Recommended Verification Query Families
Section titled “Recommended Verification Query Families”- Temporal integrity checks
- Uniqueness and duplicate detection checks
- FK orphan checks
- Export completeness checks for attempt and feedback history
- Competency evidence-to-state consistency checks
- Sync operation linkage completeness checks
Implementation Anchors
Section titled “Implementation Anchors”- Migration files and ordering:
packages/db - Migration-aware contract updates:
packages/domain - Sync linkage and mutation tracing:
packages/offline-dataandapps/api
Open Decisions
Section titled “Open Decisions”- Whether
last_operation_idis enforced FK tooperations_log.idor a validated non-FK operation identifier - Whether portability verification queries become CI-gated from phase 3 onward
- Whether competency state transitions get explicit dedicated table in v1 or v1.1