-- Migration: zoom_analytics_attendee_summary — unique key for general attendees (by email)
-- Description: General attendees (joined via the shared/common link, email carries no
--              +reg<registrationId> tag) get a summary row with registration_id NULL. Postgres
--              treats every NULL in a unique index as distinct from every other NULL, so the
--              existing (session_id, registration_id) unique index does nothing to keep one row
--              per general attendee — without this index, upserting a general attendee's row could
--              never find its own previous write and would insert a duplicate on every
--              reconcile/sync pass. This partial index gives general rows their own per-email
--              uniqueness, scoped to session_id, without touching the existing registered-seeker key.
-- Idempotent — safe to re-run.

CREATE UNIQUE INDEX IF NOT EXISTS uq_zoom_analytics_attendee_summary_session_email_general
  ON zoom_analytics_attendee_summary (session_id, email)
  WHERE registration_id IS NULL;
