-- 创建用户操作日志表
CREATE TABLE `t_user_log` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `user_id` varchar(64) NOT NULL COMMENT '用户ID',
    `user_name` varchar(128) DEFAULT NULL COMMENT '用户名',
    `project_id` varchar(64) DEFAULT NULL COMMENT '项目ID',
    `operation_type` varchar(64) NOT NULL COMMENT '操作类型（UPLOAD_FILE-上传文件, QA_QUESTION-智能问答, QA_MESSAGE-问答消息, VIEW_CATALOG-查看目录, CATALOG_SUMMARY-目录总结, MODEL_REPLY-大模型回复等）',
    `operation_detail` text COMMENT '操作详情',
    `related_id` varchar(64) DEFAULT NULL COMMENT '关联ID（如文件ID、会话ID等）',
    `ip_address` varchar(64) DEFAULT NULL COMMENT '操作IP地址',
    `user_agent` varchar(512) DEFAULT NULL COMMENT '用户代理',
    `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    PRIMARY KEY (`id`),
    KEY `idx_user_id` (`user_id`),
    KEY `idx_project_id` (`project_id`),
    KEY `idx_operation_type` (`operation_type`),
    KEY `idx_create_time` (`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户操作日志表';

-- 初始化一些常见的操作类型注释
INSERT INTO `t_user_log` (`user_id`, `user_name`, `operation_type`, `operation_detail`, `create_time`) 
VALUES ('system', '系统账户', 'SYSTEM_INIT', '创建用户操作日志表', NOW());

-- 删除初始化数据
DELETE FROM `t_user_log` WHERE `user_id` = 'system';