canopy-notices Data Model
Cross-link: canopy-notices API Reference · Source: migrations/
Tables
| Table | Purpose |
|---|---|
|
One row per generated notice. PDF is the canonical output; the schema deliberately omits |
|
The event-routed generation queue: the subscriber persists one row per |
|
Per-notice appeal-rights companion under 7 CFR 273.13(a)(3). One row per notice whose letter prints the hearing-rights box: |
|
The
|
|
Every retraction the superseded-notice consumer received: one row per |
|
One row per stale notice whose work item the legal-day fence re-queued: |
|
The generated ADR-018 / ADR-039 outbox and the generated consumer inbox (parked-state columns included), single-sourced in |
|
The fleet-wide idempotent-POST cache (#434 / #1463), created outside this service’s |
Relationships
Intra-database foreign keys only (relationship-only; columns live in the Tables list):
notice_work_items.notice_id back-points at notices without a FK (migration 20260721000000_notice_work_items.sql); the completion fence is the claim, not a constraint. notice_retractions shares notice_work_items' (source_event_id, notice_type) key without a FK: a retraction can be held before any work item exists.
Cross-service FKs (ADR-001 boundary)
Per ADR-001, canopy-notices holds no Postgres-level foreign keys to other services. Every UUID outside the intra-database FKs above is an application-level reference canopy-notices trusts the upstream services (the canopy-eligibility orchestrator, the program services and canopy-enrollment) to supply and never enforces in canopy_notices: household_id, recipient_person_id and subject_person_id (canopy-persons), application_id (canopy-applications, or the legacy program-local id before #1662), determination_id (the program service), adverse_action_id (canopy-enrollment) and source_event_id (the triggering envelope).
Address-confidentiality (ACP) mail routing (#1146)
Before anything renders, the work-item worker reads the household’s confidentiality election from canopy-applications (newest application, GET /v1/applications?household_id=…&limit=1) and fails closed: an unavailable signal is a retryable work-item error, never a mail-the-street-address fallback. An address_confidential / both election swaps the resolved postal block for the Address Confidentiality Program substitute address, in the form [notices.acp] in jurisdiction.toml states (#3439): form = "fixed" (the default) is one address for every participant, written in the table; form = "per_participant" is the addressee’s own substitute address, recorded on the person in canopy-persons, and the table then states no address lines. Under a per-participant program an addressee with no substitute address recorded is not mailed at home either: the item fails with a last_error that begins acp_substitute_unrecorded and stays on the retry ladder, because a worker can record the address. A pack without that table cannot mail an elected household at all (#3290): the worker renders nothing, warns, and closes the work item failed on the first attempt with a last_error that begins acp_substitute_unconfigured, for an operator to configure the substitute and requeue the item. Georgia’s ruleset omits the table until the SME-confirmed address lands (#1185), so its elected households' letters are held; case-confidential-only elections gate disclosure, not routing. The schema records only the outcome: notices.acp_applied (#1188) is TRUE iff the postal block was the substitute, and the applicant portal suppresses inline PDF streaming for confidential households unless it is. The per-participant ACP enrolment model that would supersede the config route is #1186.
Retention
Retention floors (eCFR, checked 2026-09-16): a rendered notice must stay retrievable for the case plus its appeal window. The PDFs are not in the database — they live in the S3-compatible object store (Garage in devstack) at pdf_storage_path, and their lifecycle is operator-driven on the bucket side; the DB holds the metadata and the pointer. Notice rows are SNAP program records under 7 CFR 272.1(f) — no less than 3 years from the month of origin — and outlive any open appeal that cites them (notice_id is held by canopy-appeals.appeal_requests). State series: Georgia Archives, DHS retention schedule (agency 144), series 1976-0110 "Food Stamp Administrative Files", 3 years — https://www.georgiaarchives.org/records/agencyprint/144 (checked 2026-09-18); it does not exceed the federal 3-year floor, so 7 CFR 272.1(f) governs. Rows are not deleted in production; archive moves are operator-driven, never migration-driven (ADR-016). A notice_program_data row follows its notice row: its FK has no ON DELETE, so a notice with a snapshot cannot be deleted while the snapshot stands, and the insert-only trigger refuses the snapshot’s own DELETE.
Indexes
-
idx_notices_household— household-scoped notice lookup -
idx_notices_recipient— recipient-scoped notice lookup -
idx_notices_type— list-by-type (worker portal filters) -
idx_notices_program— program-scoped notice list -
idx_notices_delivery(partial,WHERE active = true) — delivery-status work queue -
idx_notices_active_created_at_id(partial,WHERE active = true,(created_at DESC, id DESC)) — theGET /v1/noticeskeyset page cursor (#1214); serves the newest-first list as an index scan with no top-N sort -
idx_notices_date— notice-date scan for federal reporting / aging queries -
idx_notices_application— notices-by-application lookup -
idx_notices_determination— notices-by-determination lookup (appeal cross-link) -
idx_notice_work_items_due(partial,WHERE status = 'pending') — the worker’s claim scan (#1091) -
idx_notice_work_items_notice(partial,(notice_id) WHERE notice_id IS NOT NULL) — a notice’s work item, for the dispatch paths' retraction probe (#2446): the claim probes it per candidate instead of hash-joining every work item and retraction on each pass -
idx_notice_appeal_rights_notice— appeal-rights companion lookup -
idx_notices_adverse_action(partial,WHERE adverse_action_id IS NOT NULL) — the per-action evidence lookup (#1101) -
idx_notices_stale_type(partial,(notice_type) WHERE delivery_status = 'stale') — thecanopy_notices_stale_unregeneratedgauge’s per-type count of stale notices retired with no regeneration (#2460); stale rows are inactive, outsideidx_notices_delivery -
idx_notices_dispatch_due(partial,(created_at, id) WHERE active AND delivery_status = 'pending' AND pdf_storage_path IS NOT NULL) — the dispatcher’s claim scan (#1216) -
generated
event_outbox_*/event_inbox_*indexes — described once in the data-models index
Migration files
The eight event_outbox / event_inbox files (20260508000000, 20260516000000, 20260518004851, 20260713000000, 20260720000000, 20260803000000, 20260815000000, 20260904000000) are generated copies of crates/canopy-mq/outbox-migrations/ (cargo xtask outbox-migrations --write, parity-gated by --check); they are described once in the data-models index. The service-owned files, in timestamp order:
-
20260401000000_create_notices_tables.sql— original schema (notices, notice_appeal_rights; lookup + delivery indexes); deliberately omits body_text / body_html so PDF stays canonical -
20260515000000_add_notice_content_integrity.sql— #435 Pub 1075 §9 integrity columns (content_sha256,content_type,scan_status); forward-only with DEFAULTs so pre-migration rows survive -
20260608000000_add_notice_read_tracking.sql— #721 read/unread: addsnotices.read_at(nullable, no backfill); forward-only additive per ADR-016 -
20260721000000_notice_work_items.sql— #1091 work-item queue (notice_work_items+idx_notice_work_items_due) andnotices.dispatched_at -
20260727000000_action_notice_binding.sql— #1101: the adverse-action binding columns + the Chart B2cb_election_deadline+ the per-action evidence index -
20260816000000_notices_list_keyset_idx.sql— #1214: theidx_notices_active_created_at_idpartial index(created_at DESC, id DESC) WHERE active = truebacking theGET /v1/noticeskeyset page cursor; transactionalCREATE INDEX(notCONCURRENTLY— the sqlx migrator’s advisory lock deadlocks againstCONCURRENTLY's snapshot wait) -
20260901000000_notices_dispatch_claims.sql— #1216: the dispatch claim-lease + bounded-retry ledger (dispatch_claimed_at/dispatch_claimed_by/dispatch_attempts/dispatch_next_attempt_at/dispatch_last_error) andidx_notices_dispatch_dueover the dispatch-due predicate -
20261105000000_notices_acp_applied.sql— #1188 recipient-block provenance: addsnotices.acp_applied(BOOLEAN NOT NULL DEFAULT FALSE); gates the applicant portal’s letter-PDF streaming for address-confidential households -
20261128000000_work_item_delivery_channel.sql— #1639:notice_work_items.delivery_channel(mail|smsCHECK, DEFAULTmail) + theskippedstatus for non-applicable texts -
20261217000000_work_item_recipient_kind.sql— #1665:notice_work_items.recipient_kind(household_memberdefault \|authorized_representative— the rep-letter own-address path selector) -
20261224000000_work_item_superseded.sql— #1658: thenotice_work_items.statusCHECK widened withsuperseded(the20261128000000DROP + ADD shape); documentssupersededas anotices.delivery_statusvalue (no CHECK existed on that column until #2457 — aCOMMENT ON COLUMNcarried the vocabulary in-database) -
20261225000000_work_item_addressing.sql— #1941:notice_work_items.addressing(CHECK NULL \|subject\|responsible_adult_for_minor) — who a minor subject’s letter is addressed to (42 CFR 435.907(a)); additive, NULL = pre-migration rows -
20261226000000_notices_subject_person_id.sql— #1941:notices.subject_person_id— the person the notice is about when the addressee differs; NULL = the recipient is the subject -
20261227000000_notice_letterhead.sql— #2389:notices.agency_name/agency_address/agency_phone— the letterhead the notice printed, and the all-or-none CHECKnotices_letterhead_complete; additive, NULL = no letterhead recorded bypersist(a pre-migration row, which printed[notices], or a seed-loaded one; both re-render with[notices]) -
20261228000000_notice_retractions.sql— #2432:notice_retractions(source_event_id, notice_type)PRIMARY KEY +retracted_at— a retraction held until its due event arrives, so the letter is never staged -
20261229000000_work_item_caretaker_addressing.sql— #2390:notice_work_items.addressingCHECK widened withcaretaker_for_minor(the DROP + ADD shape) -
20261230000000_notice_retraction_dispatch_fence.sql— #2446:idx_notice_work_items_noticefor the dispatch paths' retraction probe, and thenotice_retractionstable COMMENT widened to every retraction -
20261231000000_notice_stale_delivery.sql— #2447:notice_regenerations(stale notice → the work item re-queued to regenerate it),staleadded to thenotices.delivery_statusCOMMENT, and a COMMENT onnotices.active. no CHECK ondelivery_statusyet, because the seed tool wrotedelivered; #2457 (20270103000000) fixed the seed and added it -
20270101000000_notice_superseded_retired.sql— #2456: restores todispatchedthe resent copies of mailed letters that the old arm 2 superseded (dispatched_atset), retires the othersupersededrows written before (active = false, never dispatched), and re-commentsnotices.activeandnotices.delivery_status -
20270102000000_notice_last_resent_at.sql— #2458:notices.last_resent_at, the latest resent copy’s hand-off, so a resend no longer overwrites the firstdispatched_at; additive, no backfill (an overwritten first instant cannot be recovered) -
20270103000000_notice_delivery_status_check.sql— #2457: normalisesdeliveredrows (the old seed value) todispatched, their NULLdispatched_atfromdelivered_at, elsecreated_at, then adds CHECKnotices_delivery_status_checkoverpending,dispatched,failed,superseded,stale -
20270104000000_notices_stale_type_idx.sql— #2460:idx_notices_stale_type, the partial index behind the unregenerated-stale gauge -
20270213000000_notice_program_data.sql— #2454:notice_program_data, the insert-only snapshot of theprogram_dataeach rendered letter printed, with no clock default oncreated_at(#2589); a notice without a row re-renders with the placeholders
All migrations are forward-only per ADR-016.