Skip to content

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

DataRetentionEnforcement
Glucose readings (paid plans)5 years, then auto-deletecron cleanOldDbLogs + plan check (see retentionDays in billing)
Glucose readings (demo user)7 dayscron cleanDemoReadings (apps/api/src/index.ts)
Patient events (demo user)7 dayscron cleanDemoReadings
Exports (files + DB rows)link valid 24h; files + rows purged at 10 dayscron 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 usercron cleanOldExports (extended to account_data_export)
ws_event7 dayscron cleanOldDbLogs (batched 5k)
api_call_log30 dayscron cleanOldDbLogs (batched 5k)
ip_geolocation_cache30 dayscron cleanOldDbLogs
Expired sessionspurged dailycron cleanExpiredSessions
Accounts scheduled for deletion30 days grace, then hard deletecron deleteScheduledUsers

retentionDays: Infinity in 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)

  1. Self-service: Profile → Delete account → 30-day grace → hard delete (user, patients, readings, events, connections, keys, links).
  2. Logout hygiene: clearPersistedHealthData() wipes locally cached health data on logout.
  3. Admin: /api/v1/admin/database export/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_dump of postgres-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_restore into a staging DB, then GET /readyz must 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).