Data retention & deletion
Glucose data is special-category health data (GDPR Art. 9). This page is the single source of truth for retention.
Retention table
| Data | Retention | Enforcement |
|---|---|---|
| Glucose readings (paid plans) | 5 years, then auto-delete | cron cleanOldDbLogs + plan check (see retentionDays in billing) |
| Glucose readings (demo user) | 7 days | cron cleanDemoReadings (apps/api/src/index.ts) |
| Patient events (demo user) | 7 days | cron cleanDemoReadings |
| Exports (files + DB rows) | link valid 24h; files + rows purged at 10 days | cron cleanOldExports (expiresAt +24h on creation) |
| Account data exports (“Descargar mis datos”, GDPR art. 15/20) | link valid 24h; files + rows purged at 10 days; max 1 request / 24h per user | cron cleanOldExports (extended to account_data_export) |
ws_event | 7 days | cron cleanOldDbLogs (batched 5k) |
api_call_log | 30 days | cron cleanOldDbLogs (batched 5k) |
ip_geolocation_cache | 30 days | cron cleanOldDbLogs |
| Expired sessions | purged daily | cron cleanExpiredSessions |
| Accounts scheduled for deletion | 30 days grace, then hard delete | cron deleteScheduledUsers |
retentionDays: Infinityin older billing plans means “no auto-delete yet”. New plans should set an explicit value; the table above is the documented promise regardless of the plan flag.Log retention (api_call_log, push/email logs, rule executions…) is configurable per table in the admin console at /admin/cleanup (age caps, per-group caps, glucose downsampling). Everything ships disabled by default — enabling it overrides the cron defaults above.
Deletion (right to erasure)
- Self-service: Profile → Delete account → 30-day grace → hard delete (user, patients, readings, events, connections, keys, links).
- Logout hygiene:
clearPersistedHealthData()wipes locally cached health data on logout. - Admin:
/api/v1/admin/databaseexport/import is manual and audited; restores do not resurrect hard-deleted users.
Audit log
admin_audit_log (billing schema) records admin exports/imports, plan
changes and referral claims. Health-data reads via shared links and public
API keys are logged in api_call_log (30d). Extend to per-patient read
audits before onboarding clinics.
Self-hosting backups (Coolify + R2)
Backups are not in git or in CI — they live in the platform:
- Coolify → Backups → scheduled
pg_dumpofpostgres-data→ Cloudflare R2 (offsite, versioned). - RPO/RTO are defined by the Coolify schedule (e.g. daily + 7 retained).
- Valkey (
valkey-data) is ephemeral and excluded from backups. - Test restores quarterly:
pg_restoreinto a staging DB, thenGET /readyzmust return{"status":"ready"}.
TLS terminates at the Coolify/Cloudflare proxy; the API only sends HSTS in
production. Disk encryption at rest is provided by the host/R2, not by the app
(AES-GCM ENCRYPTION_KEY covers stored CGM credentials only).