Product Decisions This Supports
- Database Maintenance Automation: Eliminates manual cleanup of stale stats/logs, reducing operational overhead and developer time spent on cron jobs or one-off scripts.
- Scalability for Analytics/Logging: Enables automated purging of old records in high-volume tables (e.g., user activity logs, session data, or analytics dashboards) without manual intervention.
- Compliance/Retention Policies: Supports GDPR/retention requirements by automating deletion of outdated data (e.g., "delete logs older than 6 months").
- Performance Optimization: Prevents bloated tables from degrading query performance by proactively cleaning up historical data.
- Roadmap for Observability: Aligns with initiatives to improve system reliability by reducing clutter in monitoring tables (e.g., Prometheus metrics, error logs).
- Build vs. Buy: Avoids reinventing a generic cleanup solution, leveraging a lightweight, focused package instead of custom code.
When to Consider This Package
-
Use this when:
- You have statistics/log tables with a
date/datetime column that grow unbounded (e.g., user_actions, system_metrics).
- You need automated cleanup without writing custom cron jobs or queries.
- Your team lacks bandwidth to maintain ad-hoc cleanup scripts.
- You’re using Symfony/Laravel and want minimal integration effort (annotation-based).
- You prioritize batch processing (configurable
batchSize) to avoid locking tables during cleanup.
-
Look elsewhere if:
- Your cleanup logic requires complex conditions beyond date-based filtering (e.g., soft deletes, foreign key checks).
- You need real-time purging (this is for scheduled batch jobs).
- Your tables lack a
date/datetime column for filtering.
- You’re in a high-security environment where custom audit trails are mandatory (this lacks event logging by default).
- You prefer event-driven architectures (e.g., triggering cleanup via message queues) over command-line scheduling.
How to Pitch It (Stakeholders)
For Executives:
"This package automates the cleanup of outdated stats/logs in our database—saving dev time, improving performance, and ensuring compliance with retention policies. For example, it can automatically purge user activity logs older than 3 months with a single command, reducing manual maintenance by 80%. It’s a low-risk, high-impact solution that integrates seamlessly with our existing Symfony/Laravel stack."
For Engineers:
*"The StatsTablesCleanerBundle provides a zero-configuration way to clean up stale records in stats/log tables using Doctrine annotations. Key benefits:
- Annotation-driven: Add
@CleanOldData to your entity (e.g., StatsEntry) and define retention rules (e.g., -3 months).
- Batch processing: Avoids table locks with configurable
batchSize (default: 500).
- Scheduled execution: Run via CLI (
php bin/console stats-tables-cleaner:clean) or integrate with your scheduler (e.g., cron).
- Lightweight: No dependencies beyond Symfony/Laravel core.
Use case: If your user_sessions table is bloating your DB, this handles it automatically—no more writing custom queries or scripts. Ideal for analytics, logs, or any time-series data."*
For Data/Compliance Teams:
"This tool ensures automated adherence to data retention policies (e.g., GDPR, internal SLAs) by purging outdated records from stats/log tables. For instance, you can enforce a 6-month retention window for error logs with zero manual effort. The bundle logs cleanup events to the console, and you can extend it to emit notifications (e.g., via eventName parameter) for audit trails."