Skip to content

AuditLog and ProcessedWebhook grow unbounded — add TTL or archival #50

Description

@projectamazonph

Problem

Two tables grow without bound:

  1. AuditLog — every admin mutation logs here (per ADR-014). No TTL, no partitioning, no archival strategy.
  2. ProcessedWebhook — PayMongo webhook idempotency log. Old entries (>30 days) serve no purpose but accumulate forever.

Impact

  • Slow queries on AuditLog as row count grows (admin dashboard, analytics)
  • ProcessedWebhook becomes noise — idempotency window is hours, not months
  • Storage costs on Neon increase monotonically

Suggested Fix

ProcessedWebhook: Add a scheduled cleanup job (e.g., Vercel cron or a script) that deletes rows older than 30 days.

AuditLog: Two options:

  • Partition by month (Postgres native partitioning) — keeps queries fast, old partitions can be detached/archived
  • Archive + truncate — export to cold storage, then delete rows older than 12 months

Either way, add a createdAt-based TTL policy.

References

  • prisma/schema.prisma lines 816-833 (AuditLog)
  • prisma/schema.prisma lines 762-779 (ProcessedWebhook)
  • AGENTS.md rule 5: Every admin action logs to AuditLog

Severity: Consider — operational debt, not urgent but compounds over time

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions