Files
pad/internal/store/migrations/070_email_verified.sql
T
xarmian 6a63fba188 feat(store): add users.email_verified_at column + model plumbing (TASK-1935) (#805)
Wave 1 of PLAN-1933 (email verification). Pure infra — nothing reads the
column until Wave 3, so this is behaviourally a no-op and mergeable early.

- Migration 070 (SQLite) / 048 (Postgres): add nullable email_verified_at
  TEXT, mirroring disabled_at. UNCONDITIONALLY backfill every existing row
  to verified (RFC3339 'Z'-suffixed) so no existing / OAuth / self-host
  account is write-locked on deploy (inverted vs password_set's conditional
  backfill). SQLite ALTER without IF NOT EXISTS; Postgres with it.
- SAFE default = verified (DR-3): CreateUser / CreateOAuthUser write a
  verified timestamp unless UserCreate.Unverified is explicitly requested
  (only the future cloud self-serve branch will set that). A missed call
  site fails SAFE (verified), not write-locked.
- models.User.EmailVerifiedAt + IsEmailVerified() (mirror IsDisabled).
- Update userColumns + BOTH scan sites (scanUser AND the inline SearchUsers
  scan) so the admin user list keeps working.
- Expose derived email_verified bool in sessionUserPayload for a later wave.

Gates: make check + make test-pg both green (dual-dialect verified).

Claude-Session: https://claude.ai/code/session_01HxBkAMiFBtCRJ2tKSCt3ST
2026-07-04 00:45:48 -04:00

26 lines
1.6 KiB
SQL

-- Add email_verified_at column for email verification (PLAN-1933 Wave 1 / TASK-1935).
-- NULL = unverified, non-NULL = the time the email was verified. Mirrors
-- disabled_at's nullable-timestamp shape. Pure infra — nothing reads this column
-- until Wave 3, so this migration is a no-op behaviourally.
--
-- NOTE: no `IF NOT EXISTS` — SQLite's ALTER TABLE ADD COLUMN rejects it.
-- NOTE: no expression DEFAULT either — SQLite forbids a parenthesised/CURRENT_*
-- default on ADD COLUMN, so the column defaults to NULL. The SAFE default
-- (verified) is enforced in the application layer instead: store.CreateUser /
-- CreateOAuthUser write a verified timestamp unless a creation path explicitly
-- requests unverified. The ONLY path that will ever leave this NULL is the
-- future cloud self-serve signup branch (Wave 3), which does not exist yet.
ALTER TABLE users ADD COLUMN email_verified_at TEXT;
-- Backfill: UNCONDITIONALLY mark EVERY existing row verified. Existing / OAuth /
-- self-host accounts predate email verification and must NOT be write-locked on
-- deploy. This is INVERTED vs password_set's conditional (oauth-aware) backfill:
-- there is no "was this user ever verified?" signal to key on, and the correct
-- answer for every pre-existing account is "verified". Emit RFC3339 with a 'Z'
-- suffix so Go's time.Parse(time.RFC3339, …) / store.parseTime reads it back
-- (the default datetime(...) 'YYYY-MM-DD HH:MM:SS' output is space-separated and
-- un-parseable by RFC3339) — same convention as disabled_at / created_at.
UPDATE users
SET email_verified_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now')
WHERE email_verified_at IS NULL;