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
+2
View File
@@ -296,6 +296,8 @@ CREATE INDEX IF NOT EXISTS idx_audit_logs_actor
ON audit_logs(actor_user_id);
CREATE INDEX IF NOT EXISTS idx_audit_logs_tenant_action
ON audit_logs(tenant_id, action);
CREATE INDEX IF NOT EXISTS idx_audit_logs_created_at
ON audit_logs(created_at);
CREATE TABLE IF NOT EXISTS knowledge_tags (
id VARCHAR(36) PRIMARY KEY,