Files
HealthLog/prisma/migrations/0178_v1187_session_expiry_indexes/migration.sql
T
Marc-André Bombeck b3d303217c perf(db): index session and challenge expiry columns
The sliding-30-day session reaper and the passkey-challenge sweep both
filter on expires_at, but neither sessions nor auth_challenges indexed
that column, so the cleanup degraded to a sequential scan on a busy
instance. Every sibling expiry table already indexes its expiry column;
add the two missing indexes via migration 0178.
2026-06-19 20:52:31 +02:00

20 lines
940 B
SQL

-- v1.18.7 — expiry indexes for the two tables swept by the session reaper.
--
-- `sessions` (sliding-30-day session expiry) and `auth_challenges` (passkey
-- registration / authentication challenges) are both pruned on `expires_at`,
-- but neither carried an index on that column. On a busy multi-user instance
-- the cleanup degraded to a sequential scan. Every sibling expiry table
-- (`refresh_tokens`, `whoop_oauth_states`, `idempotency_keys`,
-- `withings_oauth_states`, …) already indexes its expiry column; this brings
-- the two stragglers in line. Additive; no data touched.
--
-- Reversibility (down):
-- DROP INDEX IF EXISTS "sessions_expires_at_idx";
-- DROP INDEX IF EXISTS "auth_challenges_expires_at_idx";
-- CreateIndex
CREATE INDEX IF NOT EXISTS "sessions_expires_at_idx" ON "sessions"("expires_at");
-- CreateIndex
CREATE INDEX IF NOT EXISTS "auth_challenges_expires_at_idx" ON "auth_challenges"("expires_at");