Files
LWLT-AIBOT/control-plane/migrations/008_persistent_sessions.sql
2026-08-25 10:33:29 +08:00

21 lines
641 B
SQL

-- Formal platform sessions remain active until explicitly revoked. Keep the
-- historical columns for compatibility and auditability, but allow active
-- sessions to carry NULL expiration values.
ALTER TABLE sessions
ALTER COLUMN expires_at DROP NOT NULL,
ALTER COLUMN idle_expires_at DROP NOT NULL;
UPDATE sessions
SET revoked_at = now()
WHERE revoked_at IS NULL
AND (expires_at <= now() OR idle_expires_at <= now());
UPDATE sessions
SET expires_at = NULL,
idle_expires_at = NULL
WHERE revoked_at IS NULL;
CREATE INDEX IF NOT EXISTS sessions_token_active_idx
ON sessions (token_hash)
WHERE revoked_at IS NULL;