-- 010_chat_reactions.sql
-- Table des réactions emoji sur les messages de chat
-- Idempotente via IF NOT EXISTS

CREATE TABLE IF NOT EXISTS chat_message_reactions (
    id          SERIAL PRIMARY KEY,
    message_id  INTEGER NOT NULL REFERENCES chat_messages(id) ON DELETE CASCADE,
    user_id     INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    emoji       VARCHAR(10) NOT NULL,
    created_at  TIMESTAMPTZ DEFAULT NOW(),
    UNIQUE (message_id, user_id, emoji)
);

CREATE INDEX IF NOT EXISTS idx_reactions_message_id
    ON chat_message_reactions(message_id);
