mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(coderd/database/dbpurge): add retention for audit logs (#21025)
Add configurable retention policy for audit logs. The DeleteOldAuditLogs query excludes deprecated connection events (connect, disconnect, open, close) which are handled separately by DeleteOldAuditLogConnectionEvents. Disabled (0) by default. Depends on #21021 Updates #20743
This commit is contained in:
@@ -253,3 +253,20 @@ WHERE id IN (
|
||||
ORDER BY "time" ASC
|
||||
LIMIT @limit_count
|
||||
);
|
||||
|
||||
-- name: DeleteOldAuditLogs :execrows
|
||||
-- Deletes old audit logs based on retention policy, excluding deprecated
|
||||
-- connection events (connect, disconnect, open, close) which are handled
|
||||
-- separately by DeleteOldAuditLogConnectionEvents.
|
||||
WITH old_logs AS (
|
||||
SELECT id
|
||||
FROM audit_logs
|
||||
WHERE
|
||||
"time" < @before_time::timestamp with time zone
|
||||
AND action NOT IN ('connect', 'disconnect', 'open', 'close')
|
||||
ORDER BY "time" ASC
|
||||
LIMIT @limit_count
|
||||
)
|
||||
DELETE FROM audit_logs
|
||||
USING old_logs
|
||||
WHERE audit_logs.id = old_logs.id;
|
||||
|
||||
Reference in New Issue
Block a user