canopy-rules Data Model
Cross-link: canopy-rules API Reference · Source: migrations/
Tables
| Table | Purpose |
|---|---|
|
Per-evaluation audit row. One row per audited |
|
The #680 corpus-version history for non-persisting dry-run replay (ADR-027 §6, ADR-028). One row per |
|
The generated ADR-018 / ADR-039 outbox and the generated consumer inbox, single-sourced in |
|
The fleet-wide idempotent-POST cache (#434 / #1463), created outside this service’s |
rule_sets no longer exists. The original schema (20260326000000) provisioned it as a startup-cache table that auto-imported JDM files; the JDM ruleset rewrite (see the JDM ruleset rewrite plan, Step 2.5) replaced it with direct filesystem serving via a NamedFilesystemLoader wrapping zen-engine’s FilesystemLoader. Migration 20260412000000 drops the now-vestigial table; rule_evaluations.rule_set_name is intentionally a TEXT column (not an FK) so the drop is safe for the audit trail.
Relationships
No table in canopy_rules references another: the audit trail, the corpus-version history and the generated outbox/inbox are independent. ruleset_corpus_versions is keyed by corpus_hash; rule_evaluations carries no corpus hash at all — its columns are id, rule_set_name, context_type, context_id, input, output, duration_ms and created_at (20260326000000_create_rules_tables.sql; ADR-006 Amendment 2) — so the two tables share no value, there is no FK, and there is no ER diagram to draw. The corpus an evaluation ran against is returned on the wire as EvaluateResponse::corpus_hash (crates/canopy-contracts-rules/src/rule_sets.rs), not persisted here.
Cross-service FKs (ADR-001 boundary)
canopy-rules holds no Postgres-level foreign keys to other services. rule_evaluations.context_id is an opaque UUID supplied by the caller (canopy-snap, canopy-tanf, canopy-medicaid, canopy-caps, canopy-wic, canopy-eligibility); canopy-rules makes no attempt to validate it against any other database. The rule_set_name column is also unenforced — it refers to a logical name in the filesystem ruleset loader, not a DB row. This is intentional: rulesets evolve via JDM file revisions in the configuration layers, and the audit trail must remain readable even after a ruleset is renamed or retired. event_outbox likewise holds no cross-service FKs — its payload is a self-contained JSON event envelope routed by routing_key, with no DB-level reference to any consumer.
Retention
Retention floors (eCFR, checked 2026-09-16): a rule_evaluations row must outlive every determination that cites it, so the program floors govern — SNAP program records no less than 3 years from the month of origin of each record (7 CFR 272.1(f)); Medicaid the active case plus a minimum of 3 years (42 CFR 431.17(c)(1)) and fiscal records 3 years from submission of the final expenditure report, longer while audit findings are unresolved (42 CFR 433.32(b)–(c)); TANF the HHS award-record floor of 3 years from the final financial report (2 CFR 200.334, applied to HHS awards by 2 CFR 300.1 — 45 CFR part 75 was removed effective 2025-10-01, 89 FR 80055); CCDF 3 years from submission of the financial reports (45 CFR 98.90(e)). State series, one per program (Georgia Archives, checked 2026-09-18): DHS retention schedule (agency 144) — https://www.georgiaarchives.org/records/agencyprint/144 — series 1976-0110 "Food Stamp Administrative Files" (3 years) for SNAP, 1973-0476 "Public Assistance Authorization Files" (3 years or until resolution of audit, whichever is longer) for TANF and 1982-0547 "Public Assistance Client Medical Eligibility Closed Case Files" (Central Medical Eligibility Office, 3 years after the client is no longer eligible for assistance) for Medicaid; DECAL retention schedule (agency 157) — https://www.georgiaarchives.org/records/agencyprint/157 — series 0469-06-003 "Childcare and Parent Services (CAPS)" (3 years after the end of the calendar year) for CCDF. Each state series matches its federal floor’s 3-year length and differs only in trigger, so the later-ending of the state and federal windows governs a rule_evaluations row. In practice rule_evaluations and ruleset_corpus_versions are append-only and retained indefinitely; archive moves are operator-driven, never migration-driven (ADR-016).
Indexes
-
idx_rule_evaluations_rule_set_name— per-ruleset evaluation listing (regression analysis, audit replay) -
idx_rule_evaluations_context— composite(context_type, context_id)for retrieving the evaluation history of a specific determination -
ruleset_corpus_versionsPK(corpus_hash, ruleset_name)— the idempotentON CONFLICT DO NOTHINGboot insert and the?corpus_hash=replay lookup -
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:
-
20260326000000_create_rules_tables.sql— original schema (rule_setsstartup cache +rule_evaluationsaudit trail) with the per-rule-set-name and per-context indexes -
20260412000000_drop_rule_sets_table.sql— drops therule_setscache table after the JDM ruleset rewrite moved ruleset serving to the filesystem viaNamedFilesystemLoader;rule_evaluationsis untouched -
20260626000000_create_ruleset_corpus_versions.sql— #680 corpus-version history table, primary-keyed(corpus_hash, ruleset_name)for idempotent boot insert and corpus-version replay -
20260805000000_v7_pk_defaults.sql— #1173: drops thegen_random_uuid()(UUID v4) DEFAULT onrule_evaluations.id; the application binds a v7 id at every INSERT, so a missed bind now fails loud instead of minting a time-unordered v4
All migrations are forward-only per ADR-016.