CREATE TABLE IF NOT EXISTS public.ui_request_log (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    method TEXT NOT NULL,
    path TEXT NOT NULL,
    athena_url TEXT NOT NULL,
    client_name TEXT,
    status_code INTEGER,
    duration_ms DOUBLE PRECISION,
    error_message TEXT,
    request_body JSONB,
    response_preview TEXT,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_ui_request_log_created ON public.ui_request_log(created_at DESC);
CREATE INDEX IF NOT EXISTS idx_ui_request_log_client ON public.ui_request_log(client_name);
CREATE INDEX IF NOT EXISTS idx_ui_request_log_path ON public.ui_request_log(path);
