CREATE TABLE IF NOT EXISTS room_compact_summary
(
    id                 uuid                       NOT NULL
        PRIMARY KEY,
    room               uuid                       NOT NULL,
    from_seq           bigint                     NOT NULL,
    to_seq             bigint                     NOT NULL,
    summary            text                       NOT NULL,
    message_count      integer                    NOT NULL,
    source_message_ids jsonb DEFAULT '[]'::jsonb  NOT NULL,
    created_at         timestamp with time zone   NOT NULL,
    updated_at         timestamp with time zone   NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_room_compact_summary_room_to_seq
    ON room_compact_summary (room, to_seq DESC);
