-- 0010_operation_logs.sql (MySQL)

CREATE TABLE IF NOT EXISTS operation_logs (
    id              INT AUTO_INCREMENT PRIMARY KEY,
    user_id         INT             DEFAULT NULL,
    username        VARCHAR(50)     DEFAULT NULL,
    action          VARCHAR(50)     NOT NULL,
    target_type     VARCHAR(50)     NOT NULL,
    target_ids      TEXT            NOT NULL,
    target_summary  TEXT            DEFAULT NULL,
    detail_json     TEXT            DEFAULT NULL,
    ip              VARCHAR(45)     DEFAULT NULL,
    user_agent      VARCHAR(500)    DEFAULT NULL,
    created_at      DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE INDEX idx_oplog_created    ON operation_logs(created_at DESC);
CREATE INDEX idx_oplog_user_time  ON operation_logs(username, created_at DESC);
CREATE INDEX idx_oplog_action     ON operation_logs(action, target_type, created_at DESC);
