Add DB retention/pruning to stop the database growing forever - #21
Open
ashleigh-byte wants to merge 2 commits into
Open
Add DB retention/pruning to stop the database growing forever#21ashleigh-byte wants to merge 2 commits into
ashleigh-byte wants to merge 2 commits into
Conversation
metrics/device_scans/speedtest rows accumulate indefinitely today -- existing queries only ever read a 24h window, but nothing ever deletes older rows, so a long-running install's DB grows without bound. - New RETENTION_DAYS config (default 90 days) - DB.prune_old_data() deletes metrics older than the retention window (cascading to their linked speedtest row via existing ON DELETE CASCADE), then removes any device_scans rows left orphaned by that cascade -- device_scans has no timestamp of its own, but every scan is created in the same transaction as exactly one metric via speedtest, so "no linked speedtest row remains" is an equivalent age check - Runs once per detailed-report cycle (not every cycle -- no need to hit the DB with a cleanup pass every SLEEP_TIME tick) Test plan: - Unit-tested prune_old_data: old rows deleted and cascade correctly removes orphaned device_scans, recent rows survive untouched, idempotent re-run is a no-op, retention-day boundary (91 days deleted vs 89 days kept for a 90-day window) - Verified get_metrics/get_metrics_with_device_counts still return correct results post-prune - Unit-tested RETENTION_DAYS config validation (default, override, negative value rejected)
Adds RETENTION_DAYS to the .env variables table and notes the automatic pruning behavior in the Features & Workflow overview.
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.
metrics/device_scans/speedtest rows accumulate indefinitely today -- existing queries only ever read a 24h window, but nothing ever deletes older rows, so a long-running install's DB grows without bound.
Test plan: