-- Migration 142: Discord Action Log (REQ-2026-04-15-discord-action-log)
-- Audit trail for Arbiter's Discord actions: reaction roles, welcomes, DMs.

CREATE TABLE IF NOT EXISTS discord_action_log (
    id SERIAL PRIMARY KEY,
    action_type VARCHAR(50) NOT NULL,
    discord_id VARCHAR(50),
    username VARCHAR(100),
    details JSONB DEFAULT '{}',
    success BOOLEAN DEFAULT TRUE,
    error_message TEXT,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_discord_action_log_discord_id
  ON discord_action_log(discord_id);
CREATE INDEX IF NOT EXISTS idx_discord_action_log_action_type
  ON discord_action_log(action_type);
CREATE INDEX IF NOT EXISTS idx_discord_action_log_created_at
  ON discord_action_log(created_at DESC);
