-- depends_on: room_message
CREATE TABLE IF NOT EXISTS message_read (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    message UUID NOT NULL,
    room UUID NOT NULL REFERENCES room(id),
    "user" UUID NOT NULL,
    read_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    UNIQUE (message, "user")
);

CREATE INDEX IF NOT EXISTS idx_message_read_room_user ON message_read (room, "user");
CREATE INDEX IF NOT EXISTS idx_message_read_message ON message_read (message);
