feat(migration): add index on created_at for audit_logs

Introduced an index on the created_at column of the audit_logs table to optimize the daily retention sweep, improving performance by reducing the need for full table scans during deletions. This change enhances the efficiency of the retention process, particularly for tenants with high RBAC traffic. The corresponding down migration includes the removal of this index.

Refs: #1303
This commit is contained in:
wizardchen
2026-05-15 20:18:32 +08:00
committed by lyingbug
parent ff1f03ce0d
commit 3fbc271e7c
3 changed files with 13 additions and 0 deletions
@@ -17,6 +17,7 @@ BEGIN
RAISE WARNING '[Migration 000044 down] Dropping audit_logs — durable history will be lost';
END $$;
DROP INDEX IF EXISTS idx_audit_logs_created_at;
DROP INDEX IF EXISTS idx_audit_logs_tenant_action;
DROP INDEX IF EXISTS idx_audit_logs_actor;
DROP INDEX IF EXISTS idx_audit_logs_tenant_id_desc;