Used wider UNION backfill in 007 (categories OR template_items) per Pitfall 3 guidance — protects v1.0 users with templates but no categories
Migration 006 wraps deduplication DELETE and ADD CONSTRAINT in single BEGIN/COMMIT for atomicity
duration
completed
tasks_completed
tasks_total
4 minutes
2026-04-20
3
3
Phase 06 Plan 01: DB Safety Constraints and First-Run Flag Summary
One-liner: Two atomic SQL migrations adding UNIQUE constraints on budgets/categories with safe deduplication, plus a setup_completed boolean on profiles with UNION backfill, synced to the TypeScript Profile interface.
Migration 007 (007_setup_completed.sql): Two statements:
ALTER TABLE profiles ADD COLUMN setup_completed boolean NOT NULL DEFAULT false
UPDATE profiles SET setup_completed = true WHERE id IN (SELECT DISTINCT user_id FROM categories UNION SELECT t.user_id FROM templates t INNER JOIN template_items ti ON ti.template_id = t.id)
TypeScript (src/lib/types.ts): Added setup_completed: boolean to the Profile interface between currency and created_at. tsc --noEmit passes cleanly.
Deviations from Plan
None — plan executed exactly as written. The UNION backfill in migration 007 was specified in the plan (per Pitfall 3 guidance from RESEARCH.md).
Known Stubs
None — this plan produces SQL DDL and a TypeScript type update; no UI or data-flow stubs.
Threat Flags
No new threat surface beyond what was documented in the plan's threat model. The UNIQUE constraints directly address T-06-01 and T-06-02. The setup_completed column is a UX routing flag with existing RLS (T-06-03 accepted).
Self-Check
supabase/migrations/006_uniqueness_constraints.sql exists — FOUND
supabase/migrations/007_setup_completed.sql exists — FOUND
src/lib/types.ts contains setup_completed: boolean — FOUND (line 16)