-- 登录审计:记录管理端/门户每次登录尝试(成功/失败与原因),供个人中心
-- 与管理端查询,满足"登录记录查看"需求。
CREATE TABLE IF NOT EXISTS gateway.login_logs (
    id uuid PRIMARY KEY,
    kind text NOT NULL CHECK (kind IN ('admin', 'portal')),
    login text NOT NULL,
    success boolean NOT NULL,
    ip inet,
    user_agent text NOT NULL DEFAULT '',
    reason text NOT NULL DEFAULT '',
    created_at timestamptz NOT NULL DEFAULT clock_timestamp()
);

CREATE INDEX IF NOT EXISTS login_logs_kind_idx
    ON gateway.login_logs (kind, created_at DESC);
CREATE INDEX IF NOT EXISTS login_logs_login_idx
    ON gateway.login_logs (login, created_at DESC);
