-- Meetings: attendee identity (PERSISTENT_BEHAVIOR.md "who is in this meeting").
-- One row per person per meeting, from whichever source saw them first:
--   calendar (invite emails, known BEFORE start) | roster (bot DOM scrape, seconds
--   after join) | manual (record-page picker) | voice (enrolled voiceprint at batch).
-- user_id stays NULL until resolved; linking once teaches a meeting_entity_alias
-- (entity_type='user') so the same display name resolves forever after.
-- meetings.series_id = recurring-meeting identity (calendar UID when available).
-- Live PG < 9.5: plain CREATE INDEX.

CREATE TABLE IF NOT EXISTS meeting_attendees (
    id           varchar(32)  NOT NULL PRIMARY KEY,
    meeting_id   varchar(32)  NOT NULL,
    company      varchar(32)  NOT NULL,
    source       varchar(16)  NOT NULL,             -- calendar | roster | manual | voice
    display_name varchar(200) NOT NULL,
    email        varchar(200),
    user_id      varchar(32),                       -- resolved Scapetime user
    joined_at    timestamp,
    left_at      timestamp,
    created      timestamp    NOT NULL DEFAULT now()
);

CREATE INDEX idx_meeting_attendees_meeting ON meeting_attendees (meeting_id);
CREATE INDEX idx_meeting_attendees_user    ON meeting_attendees (company, user_id);

ALTER TABLE meetings ADD COLUMN series_id varchar(128);
