Feature 02 task 3: Initial v1 schema migration #12

2 Commits
Author SHA1 Message Date
dev_agentandClaude Opus 5.5 7b760e87b1 Tighten v1 schema keys, weekday checks and ai_runs references
CI / ci (push) Successful in 50s
Independent review Codex gpt-6-sol high: APPROVED (0 findings)
CI / ci (pull_request) Successful in 50s
- ai_run_id in suggestion_batches and week_plans now uses the default
  refusing action instead of ON DELETE SET NULL; the ai_runs purge must
  clear references explicitly. Tested as a refused parent delete.
- Every TEXT primary key (including notification_prefs.event and
  sessions.id_hash) is NOT NULL; tested that NULL keys are rejected.
- Weekday columns use CHECK (col IN (0, 1, 2, 3, 4, 5, 6)) so fractional
  values are refused; tested with 5.5, 0.5 and 3.5.
- Composite UNIQUE tests add positive partial-overlap cases (same date
  under different plans, same plan_date for different dinners, same
  event_key on different channels, same period_key for different
  schedules).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 09:03:49 -04:00
dev_agentandClaude Opus 5.5 50b670e0a8 Add initial v1 schema migration
CI / ci (pull_request) Successful in 50s
CI / ci (push) Successful in 50s
Independent review Codex gpt-6-sol high: CHANGES_REQUIRED (1 high, 2 medium, 1 low)
migrations/0001_init.sql creates the 25 tables of the CTXD CONTEXT.MD data
model with foreign keys (default NO ACTION, so a parent with children cannot
be deleted; ai_run_id references are ON DELETE SET NULL for the 30-day
ai_runs purge), a CHECK on every enum and boolean column, and the unique
constraints the model names. Single-row settings tables are pinned to id 1.

internal/store/schema_test.go migrates a temp database with the embedded
migrations and asserts every table exists, every enum CHECK rejects an
invalid value, every named unique constraint rejects a duplicate, and
deleting a parent with children is refused.

TestMigrateEmbeddedMigrations now expects 0000_bootstrap,0001_init, and the
upgrade test migrates a bootstrap-only database to the real embedded set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 08:58:47 -04:00