-- 002_add_indexes.sql -- Additional indexes for query performance. -- Compatible with both PostgreSQL (local dev) and CockroachDB (production). -- Speed up OTP/magic-link/reset token lookup in FindValid queries. -- The existing partial index on (email, purpose, expires_at) doesn't cover the code column, -- so queries filtering on code must scan all matching rows. CREATE INDEX IF NOT EXISTS idx_auth_codes_code ON auth_codes (code) WHERE used_at IS NULL;