--- id: resolve-sessions-accountid-cascade name: Resolve sessions.accountId NOT NULL + SET NULL contradiction status: completed depends_on: [] scope: narrow risk: critical impact: phase level: implementation --- ## Description `sessions.accountId` is declared `text NOT NULL` in `sessions.md:17` but has `onDelete: SET NULL` in `table-reference.md:80`. PostgreSQL will reject the DELETE because it cannot nullify a NOT NULL column. This is a foundational schema decision — the resolution determines whether sessions survive account deletion and affects downstream cascade work. ## Decision (D1) **Make the column nullable** with `SET NULL` cascade. Orphaned sessions (account deleted) are still valuable data for audit and debugging. This follows the "live session data: nullable FK + SET NULL" cascade pattern. ## Acceptance Criteria - [ ] `sessions.accountId` is declared `text` (nullable) in `sessions.md` with an explicit note explaining why - [ ] `table-reference.md` cascade entry for `sessions.accountId → accounts.id` uses `SET NULL` and the column is documented as nullable - [ ] No other doc references `sessions.accountId` as `NOT NULL` without acknowledging the nullable change - [ ] The doc note explains the semantic: "orphaned sessions preserve conversation history for audit and debugging" - [ ] Any downstream tasks that depend on this decision (e.g., resolve-org-dual-ownership) can proceed ## References - docs/reviews/storage-architecture-review-2026-04-21.md#C01 - docs/decisions/storage-spec-phase1-resolutions.md#D1 - docs/architecture/storage/sessions.md:17 - docs/architecture/storage/table-reference.md:80 ## Notes > To be filled by implementation agent ## Summary > To be filled on completion