Files
raa-parser_poster/db/migrations/022_audit_log_retention_and_indexes.sql
T
2026-08-03 16:18:56 +05:00

16 lines
476 B
SQL

DELETE FROM audit_log
WHERE created_at < NOW() - INTERVAL '30 days';
CREATE INDEX IF NOT EXISTS idx_audit_log_created_at
ON audit_log(created_at DESC);
CREATE INDEX IF NOT EXISTS idx_audit_log_action_time
ON audit_log(action, created_at DESC);
CREATE INDEX IF NOT EXISTS idx_audit_log_actor_time
ON audit_log(actor_id, created_at DESC)
WHERE actor_id IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_audit_log_entity_time
ON audit_log(entity_type, entity_id, created_at DESC);