canopy-wic Data Model
For a contributor or maintainer reading the WIC schema: the tables below are the schema in effect after the migrations listed at the end, applied in order. Endpoint detail is on the canopy-wic API page; the shared event_outbox / event_inbox pair is described once on the data-models index. Source: migrations/.
Tables
| Table | Purpose |
|---|---|
|
The certification record (7 CFR 246.7): each row is written for one approving determination, which it names, and a person holds at most one current row. * Mid-certification termination (#2391) adds canopy-wic writes |
|
One worker’s scheduling of a household’s mid-certification terminations from one income reassessment run (#2391; the termination routes): |
|
One participant’s mid-certification termination (#2391). |
|
Each 7 CFR 246.7(j)(6) letter of a termination (#2391): |
|
One appeal’s hearing hold on one termination (#3387, 7 CFR 246.9(g); the hold routes): |
|
One signed determination per participant (ADR-035). |
|
The immutable ADR-028 input snapshot, one per determination: |
|
Per-determination DEK store for crypto-shred (ADR-036): |
|
The clinician’s assessment (7 CFR 246.7(e)) that gates certification: |
|
Each woman’s breastfeeding status (7 CFR 246.2), written by |
|
One row per scheduled household appointment, written by |
|
canopy-eligibility’s verdict on each of this service’s determinations, one row per |
|
The shared MQ pair; columns, indexes, parking and retention are on the data-models index. |
Relationships
Seven Postgres-level relationships hold in the database; every other table stands alone.
-
The snapshot’s PK/FK:
determination_snapshots.determination_id→wic_determinations(id). -
The granting determination:
wic_participants_granting_determination_fkeyis(determination_id, application_id, household_id, person_id)→wic_determinations (id, application_id, household_id, person_id), throughwic_determinations_subject_key. The ids a participant row copies therefore agree with the determination that granted it by construction, andwic_participants_determination_keygives a determination at most one participant row. -
Supersession:
wic_participants_superseded_by_fkeyissuperseded_by→wic_participants(id),DEFERRABLE INITIALLY DEFERRED, so the supersession UPDATE can name the successor that the same transaction inserts next.wic_participants_superseded_by_keygives a row at most one predecessor. -
A termination’s record:
wic_participant_terminations_participant_fkeyis(participant_id, person_id, household_id)→wic_participants (id, person_id, household_id), throughwic_participants_subject_key. -
A termination’s evidence:
wic_participant_terminations_reassessment_fkeyis(reassessment_determination_id, reassessment_application_id, household_id, person_id)→wic_determinations (id, application_id, household_id, person_id), throughwic_determinations_subject_key: the reassessment is of the terminated record’s person, in its household. A termination of one record on another’s reassessment is refused. -
The record a termination ended:
wic_participants_termination_fkeyis(termination_id, id)→wic_participant_terminations (id, participant_id), throughwic_participant_terminations_participant_key: a record can name only its own termination, so no record names another’s (cross-participant) and no termination is named by two records (multi-pointer). -
Cohorts and letters:
wic_participant_terminations_cohort_fkey→wic_termination_cohorts(id);wic_termination_notices_termination_fkey→wic_participant_terminations(id).
Cross-service identifiers (ADR-001 boundary)
Application-level only — no FOREIGN KEY crosses the database:
-
wic_participants.household_id/person_id,wic_determinations.household_id/person_id,wic_nutritional_risk_assessments.person_id,wic_breastfeeding_statuses.person_id,wic_appointments.household_id→ canopy-persons -
wic_participants.application_id,wic_determinations.application_id→ canopy-applications -
wic_termination_cohorts.household_id→ canopy-persons;wic_termination_cohorts.scheduled_byandwic_participant_terminations.cancelled_by→ the worker’s canopy subject, canopy-identity’s id for the worker (opaqueTEXT);wic_termination_notices.notice_id→ canopy-notices -
wic_nutritional_risk_assessments.assessor_worker_id→ the assessing worker’s canopy subject (canopy-identity’s id for the worker, the delegation’ssub), stored as an opaqueTEXT(#1008);wic_breastfeeding_statuses.recorded_by→ the recording worker’s canopy subject, the same opaqueTEXTshape (#3151) -
redaction_keys.subject_id→wic_determinations.idby convention (subject_kind = 'determination_snapshot'), unconstrained so a tombstone outlives the row it protected
Retention
7 CFR 246.25(a)(2) governs WIC record retention: all records for a minimum of three years following the date of submission of the final expenditure report for the period to which the report pertains — and, when litigation, a claim, a negotiation, an audit or other action involving the records began before that period ended, until all issues are resolved or the three years end, whichever is later (LII mirror, checked 2026-09-19; the eCFR refused this host; the wic.integrity.retain-program-records action in compliance/action-catalogue/wic.toml carries the same clock). canopy-wic does not handle FTI; no Pub 1075 retention floor applies. Operationally, wic_determinations and wic_participants are retained indefinitely in the production system to support transfer-of-certification (VOC) lookups, with archive moves operator-driven.
Indexes
-
idx_wic_participants_person,idx_wic_participants_status,idx_wic_participants_category,idx_wic_participants_cert_end— per-person, roster, per-category and expiring-certification reads -
wic_participants_one_current_per_person— partial UNIQUE(person_id) WHERE status IN ('active', 'temporary'): at most one current certification per person. canopy-wic maps a violation of it, matched by name through the constantONE_CURRENT_PER_PERSONinstore::participants::persist_error, to the 409wic_current_certification_exists -
wic_participants_expiration_notice_event_key— partial UNIQUE(expiration_notice_event_id) WHERE expiration_notice_event_id IS NOT NULL: one record per staged notice, and the dispatch consumer’s lookup -
wic_participants_current_end_scan—(certification_end, id) WHERE status IN ('active', 'temporary'): the lifecycle sweep’s expire-leg keyset and its overdue count -
wic_participants_unnoticed_end_scan—(certification_end, id) WHERE status IN ('active', 'temporary') AND expiration_notice_staged_on IS NULL: the lifecycle sweep’s notice-leg keyset -
wic_participant_terminations_one_scheduled— partial UNIQUE(participant_id) WHERE status = 'scheduled': at most one scheduled termination per record, mapped by name to the 409wic_termination_already_scheduled -
wic_participant_terminations_scheduled_scan—(effective_on, id) WHERE status = 'scheduled': the settle leg’s keyset -
wic_participant_terminations_list—(participant_id, created_at DESC, id DESC): a record’s newest-first termination list;wic_participant_terminations_cohort—(cohort_id) -
wic_termination_notices_one_live— partial UNIQUE(termination_id) WHERE superseded_at IS NULL: one live letter per termination;wic_termination_notices_termination—(termination_id) -
wic_termination_cohorts_household—(household_id) -
wic_determinations_reassessment_person—(person_id, created_at) WHERE purpose = 'income_reassessment': a member’s income reassessments by instant, which the schedule route reads to refuse a run a later reassessment supersedes -
wic_determinations_operation_subject_uq— partial UNIQUE(operation_id, person_id) WHERE operation_id IS NOT NULL: one determination per claimed operation and participant (#3158). canopy-wic maps a violation of it, matched by name through the constantOPERATION_SLOTinapi/persist.rs, to the 409operation_already_determined -
The UNIQUE constraints' own indexes:
wic_participants_determination_key,wic_participants_superseded_by_key,wic_participants_subject_key,wic_determinations_subject_key,wic_termination_cohorts_idempotency_keyandwic_participant_terminations_participant_key -
idx_wic_determinations_application,idx_wic_determinations_household,idx_wic_determinations_person,idx_wic_determinations_status -
idx_determination_snapshots_as_of—(as_of) -
idx_redaction_keys_subject—(subject_kind, subject_id);uq_redaction_keys_live_subject— unique(subject_kind, subject_id) WHERE shredded_at IS NULL -
idx_wic_assessments_person,idx_wic_assessments_date -
idx_wic_breastfeeding_statuses_person—(person_id, effective_date DESC, created_at DESC): a person’s newest-first list -
idx_wic_appointments_household;idx_wic_appointments_upcoming—(appointment_at) WHERE status = 'scheduled', the dashboard feed -
event_outbox_*,event_inbox_unprocessed_idx,idx_event_inbox_parked— the generated partial indexes, described on the data-models index
Migration files
-
20260413000000_create_wic_tables.sql—wic_participants,wic_determinations,wic_nutritional_risk_assessmentsand their indexes -
20260508000000_create_event_outbox.sql— generated (index page) -
20260512000000_create_wic_appointments.sql—wic_appointments(#448) with the household and upcoming-only indexes -
20260516000000_create_event_inbox.sql— generated (index page) -
20260518004851_event_outbox_lease_columns.sql— generated (index page) -
20260622000000_create_determination_snapshots.sql—wic_determinations.snapshot_hash,determination_snapshots, its append-only trigger (ADR-028) -
20260624140000_create_redaction_keys.sql—redaction_keysand its one-way guard triggers (ADR-036) -
20260709000000_drop_wic_appointments_certification_id.sql— dropswic_appointments.certification_id(#627) -
20260713000000_event_outbox_hold.sql— generated (index page) -
20260720000000_event_inbox_parking.sql— generated (index page) -
20260803000000_event_outbox_v7_pk_default.sql— generated (index page) -
20260804000000_v7_pk_defaults.sql— drops thegen_random_uuid()default onwic_appointments.id(#1173) -
20260810000000_snapshot_hash_not_null.sql— deletes pre-snapshot determinations and setssnapshot_hash NOT NULL(#911) -
20260815000000_event_outbox_claim_order_idx.sql— generated (index page) -
20260904000000_event_outbox_parking.sql— generated (index page) -
20261208000004_redaction_keys_live_subject_uq.sql— tombstones superseded live DEKs, then addsuq_redaction_keys_live_subject(#1458) -
20261224000000_redaction_keys_rewrap_guard.sql—canopy_redaction_keys_one_way_guard()admits the KEK rewrap (wrapped_dekreplaced +kek_versionstrictly increased on a live row) beside the shred (#2113) -
20270111000001_determination_status_check.sql— deletes any determination outsideapproved / denied / sanctionedwith its snapshot, inside thecanopy.snapshot_maintenancewindow, then addswic_determinations_determination_status_verdict(#628) -
20270113000000_actor_subjects.sql— retypeswic_nutritional_risk_assessments.assessor_worker_idfromUUIDtoTEXT NOT NULL, the human-only shape for the assessor’s OIDC subject (#1008); its guard refuses a database holding a nil-UUID assessor — the remedy is the reset it names,cargo xtask dev restart -
20270114000000_wic_certification_record.sql— makeswic_participantsthe certification record (#2359). Delete cutover: it first deletes everywic_participantsrow, since no existing row names its determination and nothing references the table (devstacks reseed). It then addswic_determinations_subject_key, the four columnsdetermination_id,application_id,household_idandsuperseded_by,wic_participants_determination_key,wic_participants_granting_determination_fkey,wic_participants_superseded_by_keyand the deferredwic_participants_superseded_by_fkey, replaceswic_participants_status_check(droppingtransferred; addingtemporaryandsuperseded), and addswic_participants_supersession_checkandwic_participants_one_current_per_person -
20270115000000_wic_lifecycle.sql— the certification lifecycle (#2390): addshomeless(DEFAULT falsefor the demo and test rows that exist, dropped in the next statement, so every writer states it),expired_atwithwic_participants_expired_at_check, the staged pair withwic_participants_expiration_notice_staged_checkandwic_participants_expiration_notice_event_key, the dispatched pair withwic_participants_expiration_notice_dispatched_checkandwic_participants_expiration_notice_dispatch_staged_check, and the two partial scan indexes -
20270115500000_wic_determination_purpose.sql— addswic_determinations.purpose(#2445): the column is added nullable, every existing row is backfilledevaluation(the only purpose that existed), then it is setNOT NULL, with no default, andwic_determinations_purpose_checkis added -
20270116000000_wic_terminations.sql— mid-certification termination (#2391). Delete cutover: it deletes theterminatedrows (demo-seed and test rows; none names a termination, and nothing references one), checking the deferredwic_participants_superseded_by_fkeyat the statement so no trigger event is left pending for the ALTERs. It then addswic_participants_subject_key, the three tables with their constraints and indexes, the columnstermination_idandterminated_on,wic_participants_termination_fkey,wic_participants_terminated_check,wic_participants_terminated_on_checkandwic_determinations_reassessment_person -
20270117000000_redaction_keys_created_at_no_default.sql— drops theredaction_keys.created_atdefault: the shared canopy-db store bindscreated_at(the determination’s decision instant) andshredded_at(the redaction’s) from its caller, so an insert that names nocreated_atnow fails instead of taking the database clock (#2475) -
20270209000000_decision_stamps_no_default.sql— drops the defaults of every stamp the service’s production INSERTs bind themselves:wic_participants.created_at/updated_at,wic_determinations.created_at/updated_at,wic_nutritional_risk_assessments.created_at,wic_appointments.created_atanddetermination_snapshots.created_at. An insert that names no stamp now fails instead of taking the database clock, andcargo xtask migrations-lintrefuses a new clock default (#2589) -
20270215000000_determination_verdicts.sql— thedetermination_verdictstable and itsverdictCHECK (#2322) -
20270305000000_create_wic_breastfeeding_statuses.sql— thewic_breastfeeding_statusestable, itsstatusCHECK andidx_wic_breastfeeding_statuses_person(#3151) -
20270306000000_wic_determinations_operation.sql—wic_determinations.operation_idandsigned_payload,wic_determinations_operation_signed_ckandwic_determinations_operation_subject_uq(#3158) -
20270324000000_determination_status_withheld.sql— ADR-052: replaceswic_determinations_determination_status_verdictso the list also admitswithheld; no row is rewritten. -
20270329000000_wic_termination_holds.sql— the hearing hold (#3387): thewic_termination_holdstable with its constraints and the partial indexwic_termination_holds_standing((placed_at, termination_id, appeal_id) WHERE status = 'held', the standing holds oldest first), andwic_participant_terminations_cancel_reason_checkreplaced so the list also admitsappeal_reversed; no row is rewritten. -
20270331000000_wic_termination_enacted.sql— enactment (#3387):wic_participant_terminations.enacted_atandrecord_status_before,wic_participant_terminations_status_checkreplaced so the list also admitsenacted, and the two CHECKs above; no row is rewritten. -
20270401000000_wic_termination_reversed.sql— reversal (#3387):reversed_atandreversal_outcome, the status CHECK replaced to admitreversed, the enacted CHECK replaced so a reversed termination keeps its enactment columns, and the two reversal CHECKs; no row is rewritten.
The eight generated files are byte-identical copies of crates/canopy-mq/outbox-migrations/ (the data-models index). All migrations are forward-only per ADR-016.