feat: configurable data retention for usage and audit#64
Merged
christianromeni merged 2 commits intomainfrom Apr 7, 2026
Merged
feat: configurable data retention for usage and audit#64christianromeni merged 2 commits intomainfrom
christianromeni merged 2 commits intomainfrom
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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 #46.
Adds a background cleanup job (
retention.Cleaner) that periodically deletes old rows fromusage_eventsandaudit_logsbased on per-table retention durations. Opt-in: both durations default to 0 which means "keep forever".This is a privacy/ops feature available in the Community tier. Not license-gated.
Config
Implementation highlights
Dialect.TimestampLessThan()helper so the predicate parses correctly on both SQLite (datetime(col) < datetime(?)) and Postgres (col::timestamptz < ($1)::timestamptz). Avoids the string-comparison hazard where SQLite and PostgresCURRENT_TIMESTAMPformats differ.DELETE FROM t WHERE id IN (SELECT id FROM t WHERE ts < ? LIMIT 10000)and 100ms pause between batches. Avoids long write-lock holds on SQLite.idx_usage_events_created_atandidx_audit_logs_timestamp. The existing compositeorg_id, created_atindexes are not usable by the cleanup query (no org_id predicate).Application.Start()after usage/audit loggers. LIFO shutdown order so retention stops before the write loggers.sync.Once.Tests
15 tests in
internal/retention/cleaner_test.go, all with real in-memory SQLite (no mocks):<semantics)Test plan