-- 007: Issue reactions

-- ─── Issue Reactions ──────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS issue_reaction (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    issue_id UUID NOT NULL REFERENCES issue(id) ON DELETE CASCADE,
    user_id UUID NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,
    content TEXT NOT NULL,
    target_type TEXT NOT NULL,
    target_id UUID NULL,
    created_at TIMESTAMPTZ NOT NULL,
    CONSTRAINT uq_issue_reaction UNIQUE (issue_id, user_id, content, target_type)
);
CREATE INDEX IF NOT EXISTS idx_issue_reaction_issue_id ON issue_reaction (issue_id);
CREATE INDEX IF NOT EXISTS idx_issue_reaction_user_id ON issue_reaction (user_id);
CREATE INDEX IF NOT EXISTS idx_issue_reaction_target ON issue_reaction (target_type, target_id);
