Skip to main content

Set retention policies and place legal holds

DEVELOPER GUIDE

Create retention policies safely, preview them, turn them on, and freeze a person or record with a legal hold.

Who this guide is for

Developers and superusers who apply retention and legal holds through the routes.

Why it matters

A live policy deletes or blanks data for good. Claviger ships no policy. New ones start disabled and as a dry run, so you can see the effect first.

What you will do, in one sentence

Create the policy, preview it, enable it as a dry run, then make it live with a fresh passkey.

Screens are captured from a seeded test system. Every name, address and number on the screens is invented. Prepared 15 November 2026.

1. What a policy is​

A policy names a collection, a date, a period and an action. A daily job at 02:27 server time applies the enabled policies.

FieldMeaning
collectionThe collection the policy applies to.
basisThe date the period counts from: created, updated, a date field name, or ageOut.
after, unitThe period, in days, months or years. 0 is allowed only for a named date field.
actiondelete, anonymize or archive.
filterOptional filter on the collection's own fields. Encrypted fields cannot be filtered.
A lawyer decides the periods

How long to keep each kind of record is a decision for your lawyer. Claviger ships no policy, enabled or not.

  • delete removes the row. A guard that refuses it, such as a legal hold, counts as failed.
  • anonymize blanks the personal fields of the collection's data map entry. A collection with no entry, or no personal fields, cannot have an anonymize policy enabled.
  • archive sets archived = true. The collection needs a bool field with that name.
  • ageOut counts from the day a person's isMinor turns false. The collection needs a birthDate field.

2. Create, preview, enable, go live​

A policy is always created disabled and as a dry run, whatever the request says. Records API writes are refused. Use the routes.

  1. Create the policy:

    curl -X POST https://auth.example.org/api/gdpr/retention/policies \
    -H "Authorization: $TOKEN" -H "Content-Type: application/json" \
    -d '{"collection": "pastoral_notes", "basis": "expiresAt", "after": 0, "unit": "days", "action": "archive"}'
  2. Preview it. Nothing changes:

    curl -X POST https://auth.example.org/api/gdpr/retention/run \
    -H "Authorization: $TOKEN" -H "Content-Type: application/json" \
    -d '{"preview": true, "policy": "POLICY_ID"}'
  3. Enable it with PATCH /api/gdpr/retention/policies/{id} and {"enabled": true}. The job counts it, still as a dry run.

  4. Make it real with {"dryRun": false}.

Going live needs a fresh passkey and cannot be undone

A policy that ends up enabled and live needs a fresh passkey step-up. So does a change to a live policy. A delete or an anonymize is final. The job does not audit each row, because the entry would keep the deleted data.

A policy cannot be edited or deleted while a run that includes it is unfinished.

3. What a policy never touches​

  • Rows under an active legal hold.
  • Pastoral notes with an open export hold.
  • Permanent registers and their annotation collections. A policy on one is refused on save and on run.
  • Accounts. Erasure handles them.
  • _auditLog, which has its own audit.retentionDays, and the policy, hold, data map and key tables.

4. Read a run​

Each policy reports five counts:

CountMeaning
matchedPast the period and matching the filter.
heldSkipped because of a legal or pastoral hold.
unchangedAlready in the state the action leaves.
failedA guard refused. The reason goes to the server log.
affectedDeleted, anonymized or archived. For a dry run, would be.

A run survives a restart. It stores a cursor after every batch and continues from it. One run happens at a time.

Each run writes one gdpr_retention_run audit entry with ids and counts. It is also the webhook event gdpr.retention.

A hold freezes data while a legal matter is open. It has a scope:

  • subject: a person. It covers every row the data map ties to them.
  • record: one record, with collection and recordId.

A hold also needs a reason. A reference, such as a case number, is optional.

curl -X POST https://auth.example.org/api/gdpr/holds \
-H "Authorization: $TOKEN" -H "Content-Type: application/json" \
-d '{"scope": "subject", "subject": "USER_ID", "reason": "Open matter", "reference": "CASE-001"}'

Placing and lifting need a fresh passkey. The routes are:

GET /api/gdpr/holds[?active=1]
GET /api/gdpr/holds/{id}
POST /api/gdpr/holds
POST /api/gdpr/holds/{id}/lift

While a hold is active, the job skips the rows. Nothing can delete a held record: the records API, a cascade, a hook and the job all get 409. A lifted hold stays as evidence. There is no delete.

The audit entries gdpr_hold and gdpr_hold_lift never carry the reason or the reference.

A person's export includes their holds

The export shows the scope, reason, reference and dates of a person's holds. It leaves out who placed and lifted them. The owner decided this on 2026-11-14. Whether you may tell the person about a given hold is a legal question. Raise it with your lawyer before the export runs.

6. Quick reference card​

Make a policy live​

  1. POST /api/gdpr/retention/policies.
  2. POST /api/gdpr/retention/run with preview: true.
  3. PATCH with enabled: true.
  4. PATCH with dryRun: false, with a fresh passkey.

Hold a person​

  1. POST /api/gdpr/holds with a fresh passkey.
  2. Lift it with POST /api/gdpr/holds/{id}/lift.

The admin UI has retention and hold screens. See the erasure guide.