Skip to content

digital-identity-platform-docs


digital-identity-platform-docs / supabase/functions/sgtm_access_logs_cleanup

supabase/functions/sgtm_access_logs_cleanup ​

Scheduled cleanup job that deletes old access logs based on billing plan retention settings.

Overview ​

This Edge Function enforces log retention policies by permanently deleting access logs older than the configured retention period for each container's billing plan. It calls the sgtm_delete_old_logs database function.

Endpoint ​

POST /functions/v1/sgtm_access_logs_cleanup

Authentication ​

Cron/internal - designed to run as a scheduled job via pg_cron.

Behavior ​

  • Invokes the sgtm_delete_old_logs RPC function
  • Deletes logs older than billing_plans.log_retention_days for each container
  • Returns OK on success, Error on failure

Tables Touched ​

  • sgtm_access_logs (delete via RPC)
  • sgtm_container_subscriptions (read via RPC)
  • billing_plans (read via RPC)

Notes ​

  • Destructive operation - permanently deletes logs beyond retention period
  • Idempotent - safe to run multiple times
  • Uses service role for elevated database access

Released under proprietary license.