SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;

-- 使用 utf8mb4 连接字符集，保证中文注释、中文名称和 emoji 在导入时不被降级。

ALTER TABLE admin_operation_logs
  ADD COLUMN request_id VARCHAR(64) NOT NULL DEFAULT '' COMMENT '链路请求 ID，用于排查问题' AFTER id,
  ADD COLUMN resource_id VARCHAR(80) NOT NULL DEFAULT '' COMMENT '资源 ID' AFTER resource,
  ADD COLUMN user_agent VARCHAR(255) NOT NULL DEFAULT '' COMMENT '用户代理' AFTER ip,
  ADD COLUMN http_status INT NOT NULL DEFAULT 0 COMMENT 'HTTP 状态' AFTER status,
  ADD COLUMN risk_level VARCHAR(24) NOT NULL DEFAULT 'normal' COMMENT '风险等级' AFTER http_status,
  ADD COLUMN latency_ms BIGINT NOT NULL DEFAULT 0 COMMENT '耗时毫秒值' AFTER risk_level,
  ADD INDEX idx_admin_operation_logs_request_id (request_id),
  ADD INDEX idx_admin_operation_logs_resource_id (resource_id),
  ADD INDEX idx_admin_operation_logs_risk_level (risk_level);

ALTER TABLE admin_jobs
  ADD COLUMN attempt INT NOT NULL DEFAULT 0 COMMENT '尝试次数' AFTER error,
  ADD COLUMN max_attempts INT NOT NULL DEFAULT 3 COMMENT '最大尝试次数' AFTER attempt,
  ADD COLUMN locked_by VARCHAR(120) NOT NULL DEFAULT '' COMMENT '当前锁定 worker' AFTER max_attempts,
  ADD COLUMN locked_until_ms BIGINT NULL COMMENT '锁定截止时间，UTC epoch ms' AFTER locked_by,
  ADD COLUMN artifact_path VARCHAR(255) NOT NULL DEFAULT '' COMMENT '产物路径' AFTER locked_until_ms,
  ADD INDEX idx_admin_jobs_locked_by (locked_by),
  ADD INDEX idx_admin_jobs_locked_until (locked_until_ms);
