-- Migration: Shared (recurring) webinar support for online sessions
-- Date: 2026-07-02
-- Description:
--   Enables the "same link" model where several program sessions are backed by
--   ONE recurring Zoom webinar. Each session keeps its own hdb_online_session row
--   (so the row shape stays identical to the per-session "different links" model),
--   but SHARED rows carry the same external_id/join_url and differ only by the
--   occurrence they map to.
--
--     link_mode     -- 'perSession' (default/legacy) | 'shared'
--     occurrence_id -- Zoom occurrence id this session maps to (SHARED only)
--
-- Additive and idempotent. No data change: existing rows read as PER_SESSION.

ALTER TABLE hdb_online_session
    ADD COLUMN IF NOT EXISTS link_mode VARCHAR(30) NULL;

COMMENT ON COLUMN hdb_online_session.link_mode IS
    'How the provider resource is shared: perSession (own resource, distinct link) or shared (one recurring resource across sibling sessions, same link). Null reads as perSession.';

ALTER TABLE hdb_online_session
    ADD COLUMN IF NOT EXISTS occurrence_id VARCHAR(255) NULL;

COMMENT ON COLUMN hdb_online_session.occurrence_id IS
    'Provider occurrence id (Zoom occurrence_id) this session maps to within a SHARED recurring resource; used to scope attendance sync. Null for perSession resources.';

-- Lookup: all sibling sessions of a shared webinar share the same external_id.
-- external_id is already indexed (idx on hdb_online_session.external_id), so the
-- group lookup by external_id is covered.
