Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

UN-4398 [DOCS] Document the platform audit log purge management command (#2367)

Ritwik G75b96378f769
diff --git a/backend/platform_audit/README.md b/backend/platform_audit/README.md
index 39aae350c..27f3132f1 100644
--- a/backend/platform_audit/README.md
+++ b/backend/platform_audit/README.md
@@ -252,16 +252,27 @@ configuration key (1–3650). An env value outside 1–3650 is treated as 3650
default; the purge instead skips that organisation and exits non-zero, as it
does when it cannot read the override. Every read hides events older than the
cutoff.
-Rows are physically deleted by
+### Purging expired events
+
+Rows are physically deleted by the `purge_platform_audit_events` management
+command:
```
python manage.py purge_platform_audit_events [--dry-run] [--batch-size N]
```
-Nothing schedules it: not this app, and no deployment yet. Until something
-runs it, retention only hides rows, which stay in the table, so raising an
-organisation's override later shows the hidden events again. Run it from cron
-if storage matters or a lowered retention must be final.
+- For each organisation with events, it deletes the events older than that
+ organisation's retention.
+- `--dry-run` reports how many it would delete and deletes nothing.
+- `--batch-size` sets the events deleted per transaction (default 5000). A run
+ that stops part-way keeps what it deleted, and the next run continues.
+- It never deletes by a guessed retention. An organisation whose override it
+ cannot read, or whose override is out of range, is skipped, and the command
+ then exits non-zero naming it.
+
+Run it regularly. Until it runs, retention only hides rows, which stay in the
+table, so raising an organisation's override later shows the hidden events
+again.
## What is not recorded
diff --git a/backend/platform_audit/management/commands/purge_platform_audit_events.py b/backend/platform_audit/management/commands/purge_platform_audit_events.py
index 28fa2e7b8..19f760488 100644
--- a/backend/platform_audit/management/commands/purge_platform_audit_events.py
+++ b/backend/platform_audit/management/commands/purge_platform_audit_events.py
@@ -1,7 +1,7 @@
"""Delete platform audit events older than each organisation's retention.
-Reads already hide expired events, so running this only reclaims space. It is
-not scheduled; run it from cron or by hand::
+Reads already hide expired events, so running this reclaims space and makes a
+lowered retention final. Run it regularly::
python manage.py purge_platform_audit_events --dry-run
python manage.py purge_platform_audit_events --batch-size 5000
diff --git a/backend/sample.env b/backend/sample.env
index 6897dc2bd..bee755527 100644
--- a/backend/sample.env
+++ b/backend/sample.env
@@ -345,6 +345,6 @@ MCP_BILLABLE_CALL_LIMIT=50
MCP_BILLABLE_WINDOW_SECONDS=3600
# Platform audit log (Settings > Audit log): days events stay readable. Each org
-# can override it. Expired rows are hidden, and deleted only when
-# `manage.py purge_platform_audit_events` runs (nothing schedules it).
+# can override it. Expired rows are hidden, and deleted when the
+# `purge_platform_audit_events` management command runs.
PLATFORM_AUDIT_RETENTION_DAYS=365