feat(audit): nightly retention purge for audit_log rows#49
Open
jusso-dev wants to merge 1 commit into
Open
Conversation
Adds a per-organisation purge that respects each tenant's audit_retention_days. Runs nightly at 03:00 Australia/Sydney as an Inngest cron (one hour after the existing PII scrub) and deletes in batches of 10k so it never holds a long lock on audit_log. Per-org counts are emitted via structured logs so operators can confirm what was removed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #41. The
audit_logtable and per-tenantorganisations.audit_retention_dayscolumn already shipped in #42; this adds the deletion job that respects them.lib/audit/purge.tswithpurgeAuditLogsForOrganisationandpurgeExpiredAuditLogs.WITH target_rows AS (... LIMIT ...) DELETE ...) so we never hold a long lock onaudit_log.[audit-purge] org=… retention=…d cutoff=… deleted=… batches=…).audit-log-retention-purgeregistered alongsideeventRetentionSweepand scheduled at0 3 * * *Australia/Sydney — 30 min after the existing PII scrub so the two jobs don't fight for the table.Test plan
created_atstraddling the cutoff, runpurgeAuditLogsForOrganisation, confirm only rows older than the org's retention window are removed.audit-log-retention-purgeregistered after deploy.https://claude.ai/code/session_01PiiqDRQJdW1sBLvEmZ3GBC
Generated by Claude Code