-- Migration: Online Program Attendance — attendance event log
-- Description: Adds a single JSONB event log to program_user_attendance. Every
--              attendance action (JOIN_CLICK, ZOOM_WEBHOOK, MANUAL_ADMIN, QR_SCAN)
--              appends one event; summary flags (is_attended, checked_in_at) are
--              set on the first event. No separate per-join table is used.
-- Idempotent — safe to re-run.

ALTER TABLE program_user_attendance
  ADD COLUMN IF NOT EXISTS attendance_events JSONB NOT NULL DEFAULT '[]';

COMMENT ON COLUMN program_user_attendance.attendance_events IS 'Append-only audit log of attendance events: [{ source, occurredAt, performedBy }]';

