-- Create room_message_reaction table
CREATE TABLE IF NOT EXISTS room_message_reaction
(
    id         UUID PRIMARY KEY,
    room       UUID                     NOT NULL,
    message    UUID                     NOT NULL,
    "user"     UUID                     NOT NULL,
    emoji      VARCHAR(50)              NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    UNIQUE (message, "user", emoji)
);

-- Index for fast reaction lookups
CREATE INDEX IF NOT EXISTS idx_room_message_reaction_message ON room_message_reaction (message);
CREATE INDEX IF NOT EXISTS idx_room_message_reaction_user ON room_message_reaction ("user");
CREATE INDEX IF NOT EXISTS idx_room_message_reaction_room ON room_message_reaction (room);

-- Add full-text search column for message content
ALTER TABLE room_message
    ADD COLUMN IF NOT EXISTS content_tsv TSVECTOR;

-- Create index for full-text search
CREATE INDEX IF NOT EXISTS idx_room_message_content_tsv ON room_message USING GIN (content_tsv);
