canopy-web Data Model
For a contributor reading or migrating canopy_web: the tables that exist at runtime, where each comes from (a migration file or boot-time DDL), and the retention posture. Routes live on canopy-web API Reference; source: migrations/.
Tables
The schema in effect is the migrations applied in order plus one piece of boot-time DDL, the fleet idempotency table, listed because it exists in the database although no migration file names it.
| Table | Purpose |
|---|---|
|
The live worker web sessions on canopy-identity (ADR-009 Amendment 2 — never |
|
One row per device a worker approved: canopy-cli’s native session (ADR-049 Amendment 21). |
|
One row per sign-in, step-up or device approval in flight, written by |
|
Why each web or native session ended: a diagnostic record holding no live credential. |
|
Override storage for the composition runtime (ADR-021). One row per |
|
Explicit-archive history for promoted or superseded overrides. Created |
|
Generated ADR-018 / ADR-039 outbox and inbox (eight files in |
|
The fleet idempotency cache, created before the migrator runs by |
_sqlx_migrations (sqlx’s history table) is present as in every service.
Relationships
No table here carries a foreign key. composition_documents_archive mirrors composition_documents by LIKE derivation, not by FK. web_login_flow.replaces_session_id and web_session_end.superseded_by name web_session ids by value only, and web_session_end.session_id names a web_session or web_native_session id: the session they name may already have ended.
Cross-service FKs (ADR-001 boundary)
canopy-web holds no Postgres-level foreign key to any other service. The columns that name identities elsewhere are application-level only: composition_documents.jurisdiction_id (a UUID, jurisdiction config) and created_by / archived_by (TEXT OIDC subjects — workers are not canopy-persons rows); web_session.record's sub, web_native_session.subject and web_session_end.subject are the worker’s canopy subject (ADR-049), canopy-identity’s id for the worker, not an upstream’s sub. The session store holds token hashes and a worker’s own federated session, not person or household ids. canopy-web reaches every other service over HTTP.
Retention
-
web_session— transient; the 8-hour sliding idle deadline above; and the engine ends it, loggedexpired, once it can no longer be kept fresh, at the latest at the federated session’s own end (session_ends_at) (ADR-009 records the canopy-web figure as 8 hours). A row past its deadline neither loads nor accepts writes, and the next pass of the session sweeper (services/canopy-web/src/web_session/sweep.rs, #2519; every 5 minutes on every replica, Deployment Guide › Worker-session sweep) ends it, loggedidle. No regulatory floor. -
web_native_session— until the session ends, logged inweb_session_endlike a web session’s. No regulatory floor. -
web_login_flow— at most its 15-minute lifetime (FLOW_LIFETIME); the sweeper deletes a row past it. No regulatory floor. -
web_session_end— 30 days fromended_at(END_LOG_RETENTION), then deleted by the sweeper. The readers that decide something need a row for far less: a replacement’s sign-out check within a flow’s lifetime, a sign-out’ssuperseded_bywalk while a concurrent sign-in completes, and the engine’send_reasonread within a claim’s lease; the rest is diagnostics. No regulatory floor. -
event_outbox/event_inbox— the janitors documented on the data-models index. No regulatory floor. -
composition_documents/composition_documents_archive— every override write emits a JWS-signedAuditEvent(ADR-014) under the uniform 1-year override-layer retention of ADR-022 › Audit retention. Archiving is the explicit Studio promote-merge, never a destructive migration.
canopy-web holds no FTI or PHI; no Pub 1075 or HIPAA floor applies at this layer.
Indexes
-
web_session_idle_expires_at_idx— the idle sweep;token_hashisUNIQUE. The operator’s per-worker end readsrecord →> 'sub'without an index: an operator action over a table of live sessions -
web_native_session_subject_idx,web_native_session_due_at_idx— a worker’s devices, and the sweep’s due listing -
web_login_flow_expires_at_idx— expired-flow cleanup;flow_hashisUNIQUE -
web_session_end_token_hash_idx,web_session_end_ended_at_idx— the sign-out’ssuperseded_bywalk, and end-log retention -
composition_documents_lookup_idx—(jurisdiction_id, surface, layer, scope_key); the loader’s single-query fetch of every override layer for a surface -
composition_documents_archive_lookup_idx—(jurisdiction_id, surface, archived_at DESC); most-recent-first history per jurisdiction and surface -
UNIQUE (jurisdiction_id, layer, scope_key, surface)oncomposition_documents— one live override row per layer tuple (not inherited by the archive) -
idx_idempotency_keys_created_at— runtime DDL beside its table (crates/canopy-db/src/idempotency_schema.rs) -
event_outbox_*/event_inbox_*— the generated partial indexes, documented once on the data-models index
Migration files
The eight generated outbox/inbox files (20260508000000, 20260516000000, 20260518004851, 20260713000000, 20260720000000, 20260803000000, 20260815000000, 20260904000000) are documented once on the data-models index.
-
20260401000000_create_sessions_table.sql—sessions+sessions_expiry_idx, which no code ever used; dropped by20270114000000 -
20260522002115_create_composition_documents.sql— ADR-022 (#489): thecomposition_layer+composition_surfaceENUMs,composition_documents,composition_documents_archive, the two lookup indexes -
20260805000000_v7_pk_defaults.sql— #1173: drops thegen_random_uuid()iddefaults oncomposition_documentsandcomposition_documents_archive(the archive had inherited the parent’s default throughLIKE … INCLUDING DEFAULTS); ids are bound as UUIDv7 at every insert -
20270113000000_composition_actor_subjects.sql— #1008: retypescomposition_documents.created_byand the archive’screated_by/archived_byfromUUIDtoTEXT NOT NULLin one migration (archive_document'sINSERT … SELECTcopiescreated_byacross the two tables, and there is no text-to-uuid assignment cast); a stored UUID becomes its text. A guard then refuses the migration, namingcargo xtask dev restart, if any of the three holds the nil UUID, which is no one’s subject -
20270114000000_web_session_store.sql— #2518: drops the unusedsessionstable and createsweb_session,web_login_flowandweb_session_endwith their indexes (ADR-009 Amendment 2). Thetower_sessionsschema the old store created at boot is left for the operator to drop (Deployment Guide), since schema DDL does not belong in a service migration -
20270115000000_web_session_refresh_claim.sql— #2224: the Keycloak-era refresh claim columns; replaced with their table by20270201000000 -
20270201000000_identity_web_session.sql— drops the Keycloak-eraweb_session,web_login_flowandweb_session_endoutright and createsweb_session,web_native_session,web_login_flowandweb_session_endon canopy-identity, with their indexes. Every live session, pending sign-in and Studio draft is dropped; pre-1.0, workers sign in again
All migrations are forward-only per ADR-016.