@@ -114,13 +114,32 @@ create table if not exists `role_permissions` (
114114 references ` permissions` (` id` ) on delete cascade on update cascade -- 引用 permissions.id 并设置级联删除和更新
115115) engine= innodb auto_increment= 1 comment= ' 角色权限关联表' ;
116116
117+ -- 创建日志表
118+ create table if not exists ` api_logs` (
119+ ` id` bigint unsigned not null auto_increment comment ' ID' ,
120+ ` user_id` bigint unsigned not null comment ' 用户id' ,
121+ ` username` varchar (50 ) not null comment ' 用户名' ,
122+ ` path` varchar (255 ) not null comment ' 请求路径' ,
123+ ` method` varchar (10 ) not null comment ' 请求方法' ,
124+ ` query` text default null comment ' 请求参数' ,
125+ ` body` text default null comment ' 请求体' ,
126+ ` user_agent` varchar (255 ) not null comment ' 用户代理' ,
127+ ` client_ip` varchar (20 ) not null comment ' 客户端IP' ,
128+ ` status_code` int not null comment ' 状态码' ,
129+ ` duration` bigint not null comment ' 请求耗时(ms)' ,
130+ ` response_body` text default null comment ' 响应体' ,
131+ ` type` enum(' operate' , ' login' ) not null comment ' 日志类型, operate: 操作日志, login: 登录日志' ,
132+ ` created_at` timestamp not null default current_timestamp comment ' 创建时间' ,
133+ ` updated_at` timestamp not null default current_timestamp on update current_timestamp comment ' 更新时间' ,
134+ ` deleted_at` timestamp null default null comment ' 删除时间' ,
135+ primary key (` id` )
136+ ) engine= innodb auto_increment= 1 comment= ' 日志表' ;
117137
138+ -- -- 修改表
139+ -- alter table `users`
140+ -- add unique key `uk_username` (`username`),
141+ -- add unique key `uk_email` (`email`),
142+ -- add unique key `uk_phone` (`phone`);
118143
119- -- 修改表
120- alter table ` users`
121- add unique key ` uk_username` (` username` ),
122- add unique key ` uk_email` (` email` ),
123- add unique key ` uk_phone` (` phone` );
124-
125- alter table ` permissions`
126- modify column ` type` enum(' menu' , ' button' ) not null comment ' 权限类型, menu: 菜单, button: 按钮' ;
144+ -- alter table `permissions`
145+ -- modify column `type` enum('menu', 'button') not null comment '权限类型, menu: 菜单, button: 按钮';
0 commit comments