-- Migration: zoom_analytics_attendee_summary — unique key fix (registration, not email)
-- Description: The upsert was keyed on (session_id, email). One real email can legitimately
--              back several sibling registrations for the same session (proxy/child regs —
--              see buildZoomRegistrantEmail), so that key silently collapsed sibling
--              registrations' attendee rows into one, dropping their join/attendance data.
--              registration_id is the true per-seeker key. Existing rows already carry a
--              registration_id, so no data migration is needed — only the constraint.
-- Idempotent — safe to re-run.

DROP INDEX IF EXISTS uq_zoom_analytics_attendee_summary_session_email;

CREATE UNIQUE INDEX IF NOT EXISTS uq_zoom_analytics_attendee_summary_session_registration
  ON zoom_analytics_attendee_summary (session_id, registration_id);
