feat: 新增 tb_user、tb_log 表
This commit is contained in:
@@ -135,6 +135,36 @@ async def _create_tables(pool: aiomysql.Pool):
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
) 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("数据库表初始化完成")
|
logger.info("数据库表初始化完成")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user