Skip to content

feat(retention): add per-table retention policies - #776

Closed
EmmanuelOchaje wants to merge 1 commit into
SmartDropLabs:mainfrom
EmmanuelOchaje:feat/issue-685-data-retention-policy
Closed

EmmanuelOchaje wants to merge 1 commit into
SmartDropLabs:mainfrom
EmmanuelOchaje:feat/issue-685-data-retention-policy

Conversation

@EmmanuelOchaje

Copy link
Copy Markdown
Contributor

Summary

Adds per-table data retention policies to src/services/dataRetention.js so retention periods are no longer global-only.

What changed

  • New policies map keyed by table: webhook_delivery, session, audit_logs (default 90 days), temp_files (default 7 days).
  • Each policy can be overridden by env var: DELIVERY_LOG_RETENTION_DAYS, SESSION_RETENTION_DAYS, AUDIT_LOG_RETENTION_DAYS, TEMP_FILE_RETENTION_DAYS. Invalid values fall back to the default.
  • New getRetentionDays(table) helper. applyDeliveryRetention and applySessionRetention now read their period from policies.
  • policies and getRetentionDays are exported. Existing exports (DELIVERY_RETENTION_DAYS, SESSION_RETENTION_DAYS, TTL constants, and functions) are unchanged.

Why

Retention was not configurable per table, which led to over-deletion of data that should be kept and under-deletion of stale data, with compliance risk.

Notes

  • SESSION_RETENTION_DAYS keeps its existing default of 7 days to avoid changing current behavior. The issue's example suggested 30; changing that is a separate decision.
  • audit_logs and temp_files have no Redis key prefix in findExpired() yet, so their policies are defined but not yet applied to any cleanup scan. Adding scans for them would delete data and should be a follow-up.
  • Tests were not run locally. CI is the first run.

How to test

  1. Run npx eslint src/services/dataRetention.js.
  2. In Node, require('./src/services/dataRetention').policies should show the defaults (30, 7, 90, 7).
  3. Set AUDIT_LOG_RETENTION_DAYS=365 and confirm getRetentionDays('audit_logs') returns 365.

Closes #685

Add a `policies` map with per-table retention periods (webhook_delivery,
session, audit_logs, temp_files), each overridable via env var, and a
`getRetentionDays` helper. Existing delivery/session constants and exports
are unchanged.

Closes SmartDropLabs#685
@drips-wave

drips-wave Bot commented Nov 22, 2026

Copy link
Copy Markdown

@EmmanuelOchaje Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@EmmanuelOchaje

Copy link
Copy Markdown
Contributor Author

Superseded by #777, which combines this change with the other SmartDrop fixes into one PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

services/dataRetention.js: no retention policy per table

1 participant