-- Süresi dolmuş token'ları periyodik temizlemek için index (pg_cron veya uygulama seviyesi cleanup) CREATE INDEX IF NOT EXISTS idx_access_tokens_expires ON access_tokens(expires_at); CREATE INDEX IF NOT EXISTS idx_refresh_tokens_expires ON refresh_tokens(expires_at); -- Cleanup fonksiyonu — pg_cron yoksa uygulama startup'ında çağrılır CREATE OR REPLACE FUNCTION cleanup_expired_tokens() RETURNS void AS $$ BEGIN DELETE FROM access_tokens WHERE expires_at < NOW() - INTERVAL '1 hour'; DELETE FROM refresh_tokens WHERE expires_at < NOW() - INTERVAL '1 day' AND (used_at IS NOT NULL OR revoked = TRUE); END; $$ LANGUAGE plpgsql;