Threadline.Retention batches expiry of AuditChange rows and optionally
removes empty AuditTransaction rows.
Requires config :threadline, :retention with enabled: true before any
destructive run (see Threadline.Retention.Policy). Callers must pass repo:
explicitly, matching the Threadline read functions.
Cutoff is derived from Threadline.Retention.Policy.cutoff_utc_datetime_usec!/0
unless you pass cutoff: (UTC DateTime, microsecond) for a stricter window
than policy alone (operators only — must be older than the policy cutoff).
Summary
Types
An option accepted by purge/1.
Accumulator returned by purge/1 on success (counts are cumulative).
Functions
Returns purge_result() after deleting expired AuditChange rows, or
{:error, :disabled} when retention is disabled. Raises ArgumentError for
invalid policy or a cutoff newer than the policy cutoff; repository errors
are reraised.
Types
@type purge_opt() :: Threadline.repo_opt() | Threadline.storage_schema_opt() | {:batch_size, pos_integer()} | {:max_batches, pos_integer()} | {:dry_run, boolean()} | {:sleep_ms, non_neg_integer()} | {:cutoff, DateTime.t()}
An option accepted by purge/1.
@type purge_result() :: %{ deleted_changes: non_neg_integer(), deleted_transactions: non_neg_integer(), batches_run: non_neg_integer(), dry_run: boolean() }
Accumulator returned by purge/1 on success (counts are cumulative).
Functions
@spec purge([purge_opt()]) :: purge_result() | {:error, :disabled}
Returns purge_result() after deleting expired AuditChange rows, or
{:error, :disabled} when retention is disabled. Raises ArgumentError for
invalid policy or a cutoff newer than the policy cutoff; repository errors
are reraised.
The cutoff comes from Threadline.Retention.Policy; an explicit cutoff must
be older than or equal to that policy cutoff.
Options
:repo—Ecto.Repomodule. Required.:storage_schema— string. Optional. Selects the Threadline storage schema.:batch_size— positive integer. Defaults to500; maximum rows per delete pass.:max_batches— positive integer. Defaults to10_000; maximum change batches plus orphan draining.:dry_run— boolean. Defaults tofalse; when true, no deletes and returns counts of rows that would match delete predicates (:deleted_changes/:deleted_transactionsare those counts,:batches_runis0). The preview assumes the run completes; a run cut short by:max_batchesdeletes fewer.:batch_sizeand:max_batchesare ignored in dry-run mode — the preview is a single full-table count, not a batched simulation, so passing either alongsidedry_run: truehas no effect on the returned counts.:sleep_ms— non-negative integer. Defaults to50; delay between delete batches.:cutoff— UTCDateTime. Optional. Must be at or before the policy cutoff.
Other option keys are ignored.
Returns
purge_result()— cumulative deletion counts and whether the run was a dry run.{:error, :disabled}— the retention policy does not haveenabled: true.- Raises
ArgumentErrorfor invalid policy or a cutoff newer than the policy cutoff; repository errors are reraised.