Skip to main content

fastpluggy-db-purge

DB Purge Release Pipeline Status Coverage

Centralized database retention management and purge plugin for FastPluggy.

Features

  • Auto-discover all database tables with row counts and sizes
  • Per-table retention policies via admin UI
  • Plugin-declared purge targets via fp_purge_targets hook — declaring a table upserts a disabled rule an admin enables to validate (see below)
  • Manual and scheduled purge with batched deletes
  • Full audit trail of purge operations

Installation

pip install fastpluggy-db-purge

Configuration

Setting Default Description
default_retention_days 30 Global fallback retention
default_timestamp_column updated_at Global fallback timestamp column
batch_size 5000 Rows per DELETE batch
auto_purge_enabled False Enable scheduled purge
auto_purge_cron 0 4 * * * Cron schedule (daily 4am UTC)

Declaring purge targets from another plugin

A plugin can declare its own tables as purgeable from its on_load_complete():

from fastpluggy_plugin.db_purge.hooks import register_purge_target

register_purge_target("task_reports", "end_time", default_retention_days=30)

This does two things:

  1. Registers the table + declared defaults in the in-memory registry, so it shows on the DB Purge dashboard (marked declared by plugin).
  2. Upserts a persistent rule in fp_purge_rules, created disabled. An admin must enable it in the web UI before anything is deleted — a validation gate, so declaring a table can never silently purge its data.

If the plugin later changes what it declares (timestamp column or retention), the rule is refreshed and re-disabled for the admin to re-validate. Provenance is tracked by a declared_hash column: plugin-managed rows carry the hash; admin-created rows have declared_hash = NULL and are never touched by the hook.

To exclude a config/system table from purge entirely:

from fastpluggy_plugin.db_purge.hooks import register_purge_excluded

register_purge_excluded("my_plugin_config")

Observability

Audit Trail

All purge runs (manual, scheduled, and dry-run) are logged to fp_purge_logs:

-- Recent purges
SELECT table_name, rows_deleted, duration_ms, status, executed_at, executed_by
FROM fp_purge_logs
ORDER BY executed_at DESC LIMIT 20;

-- Failed purges
SELECT table_name, error_message, executed_at
FROM fp_purge_logs
WHERE status = 'error'
ORDER BY executed_at DESC;

-- Stalled purges (running > 1 hour)
SELECT table_name, executed_at, executed_by
FROM fp_purge_logs
WHERE status = 'running' AND executed_at < NOW() - INTERVAL '1 hour';

Metrics

No Prometheus metrics are exposed yet. Use the audit trail table for monitoring.

Logging

Purge lifecycle events are logged at INFO level:

[db_purge] Declared purge target (disabled, awaiting admin): task_reports
Purge task_reports: deleted 5000 rows (total: 5000)
db_purge_all: task_reports — deleted 25000 rows (success)

Errors are logged at ERROR with full tracebacks.

Failure Modes

DB statement timeout during purge

Symptom: Purge fails with statement_timeout error

Cause: Large table (>1TB) with slow DELETE or COUNT(*)

Recovery:

  • COUNT(*) is skipped automatically above 1GB (since v1.0.1)
  • Reduce batch_size setting to smaller chunks (default 5000)
  • Increase DB statement_timeout if appropriate for your workload

Hard crash mid-purge (OOM, kill -9)

Symptom: fp_purge_logs row stuck in status='running' forever

Impact: Partial rows deleted; exact count visible in rows_deleted field (updated per batch commit)

Recovery:

  1. Check rows_deleted to see progress
  2. Manually update the row to status='error' or delete it
  3. Re-run the purge (safe to retry — it's an idempotent DELETE WHERE ts < cutoff)

Known issue: #3 tracks automatic stale-running reaper

Scheduled purge keeps running after toggle OFF

Symptom: Auto-purge disabled in UI but cron still executes

Impact: P1 data loss if retention policy was changed before disabling

Recovery: Manually disable the task in the tasks_worker scheduled tasks table

Known issue: #4 tracks the fix

Purging table from uninstalled plugin

Risk: Enabled purge rule for a table whose owning plugin was uninstalled

Prevention: No automatic guard — admin must disable purge rules before uninstalling plugins

Recovery: If data was incorrectly purged, restore from DB backup

Upgrade Notes

v1.0.0 → v1.0.1+

Schema migration: declared_hash column added automatically on first load (idempotent ALTER TABLE ADD COLUMN)

Rollback: If downgrading to <1.0.0, drop the column:

ALTER TABLE fp_purge_rules DROP COLUMN declared_hash;

v0.x → v1.0.0

Breaking: Plugin-declared rules now re-disable on declaration change. Previously-enabled rules may need re-validation after upgrade.

Metadata

Release files for fastpluggy-db-purge 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastpluggy-db-purge 1.0.5
File Size Uploaded Provenance Actions
fastpluggy_db_purge-1.0.5.tar.gz 38.0 kB Without provenance Details for fastpluggy_db_purge-1.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastpluggy-db-purge 1.0.5
File Interpreter ABI Platform Actions
fastpluggy_db_purge-1.0.5-py3-none-any.whl Python 3 none any Details for fastpluggy_db_purge-1.0.5-py3-none-any.whl

Total release size: 66.7 kB

Release files / fastpluggy_db_purge-1.0.5.tar.gz

Download URL fastpluggy_db_purge-1.0.5.tar.gz
Size 38.0 kB
Tags Source
SHA-256 checksum
How to use checksums
262f2c5b1693ce0462e6bc94331d5b1de972f5d470f945c760f1a359bcfc96b0
BLAKE2b-256 checksum
How to use checksums
f71635c4e5ddb7ebda7e5a82623538ea4b4e2fdd2a2f3df4e7cb7b869f7e0ec3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / fastpluggy_db_purge-1.0.5-py3-none-any.whl

Download URL fastpluggy_db_purge-1.0.5-py3-none-any.whl
Size 28.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a93c4af9fc368d1c7e3ca2b0dfadefdda3ab4fa5ac55dedc19d22f721cd747cb
BLAKE2b-256 checksum
How to use checksums
b4d33f1cb86a37a1603ab66501fc71acec7d3d0b7fbec7f5000e6d7015c443fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Security for fastpluggy-db-purge 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page