-- 011_password_reset.sql — self-service password reset (token table). -- -- Additive and idempotent: schema.sql already carries the identical table, -- so this is a structural no-op on a fresh database and the only path that -- creates it on an installed one (db-converge proves both land the same). -- -- Tokens are random 256-bit values; only the SHA-256 hash is persisted, so -- a database leak yields no working reset links. Rows are single-use -- ("usedAt"), short-lived ("expiresAt"), and issuing a fresh token deletes -- the user's previous ones (see internal/db/password_reset.go). CREATE TABLE IF NOT EXISTS "PasswordResetToken" ( id text PRIMARY KEY, "userId" text NOT NULL REFERENCES "User"(id) ON DELETE CASCADE, "tokenHash" text NOT NULL UNIQUE, "expiresAt" timestamptz NOT NULL, "usedAt" timestamptz, "createdAt" timestamptz NOT NULL DEFAULT now() ); CREATE INDEX IF NOT EXISTS "PasswordResetToken_userId_idx" ON "PasswordResetToken"("userId");