-- Meetings PR5: debrief distribution log — who was sent which meeting artifact,
-- when, and whether it went out. One row per recipient per send.
-- Live PG < 9.5: plain CREATE INDEX, no ON CONFLICT.

CREATE TABLE IF NOT EXISTS meeting_distribution (
    id              varchar(32)  NOT NULL PRIMARY KEY,
    meeting_id      varchar(32)  NOT NULL,
    company         varchar(32)  NOT NULL,
    kind            varchar(16)  NOT NULL DEFAULT 'debrief',
    recipient_name  varchar(128),
    recipient_email varchar(200) NOT NULL,
    user_id         varchar(32),                    -- linked Scapetime user, if any
    status          varchar(16)  NOT NULL,          -- sent | failed
    error_message   text,
    sent_by         varchar(32),
    created         timestamp    NOT NULL DEFAULT now()
);

CREATE INDEX idx_meeting_distribution_meeting ON meeting_distribution (meeting_id);
