From 43fd3e7be9f5d66628f5d9bff510e9ef3eb532b8 Mon Sep 17 00:00:00 2001 From: wangfq Date: Thu, 28 May 2026 13:58:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20tb=5Fuser=E3=80=81?= =?UTF-8?q?tb=5Flog=20=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/models.py b/src/models.py index 239cd0c..4db13eb 100644 --- a/src/models.py +++ b/src/models.py @@ -135,6 +135,36 @@ async def _create_tables(pool: aiomysql.Pool): ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 """) + # 5. 用户表 + await cur.execute(""" + CREATE TABLE IF NOT EXISTS `tb_user` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `username` VARCHAR(45) UNIQUE NOT NULL, + `password_hash` VARCHAR(256) NOT NULL, + `role` VARCHAR(20) DEFAULT 'operator' COMMENT 'admin/operator', + `is_active` TINYINT DEFAULT 1, + `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 + """) + + # 6. 日志表 + await cur.execute(""" + CREATE TABLE IF NOT EXISTS `tb_log` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `user_id` INT DEFAULT 0, + `username` VARCHAR(45) DEFAULT '', + `action_type` VARCHAR(30) NOT NULL COMMENT 'login/logout/command', + `target` VARCHAR(100) DEFAULT '' COMMENT '操作对象', + `detail` VARCHAR(500) DEFAULT '' COMMENT '详情', + `result` VARCHAR(20) DEFAULT 'ok' COMMENT 'ok/error', + `ip` VARCHAR(45) DEFAULT '', + `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP, + INDEX `idx_username` (`username`), + INDEX `idx_action_type` (`action_type`), + INDEX `idx_create_time` (`create_time`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 + """) + logger.info("数据库表初始化完成")