如何设计用户权限功能

用户表
角色表
菜单表
用户关联角色表
角色关联菜单表

使用这 5 张表实现简单的用户权限功能

create table `b_user` (
    `id` bigint unsigned not null auto_increment comment '唯一标识',
    `name` varchar(32) not null comment '姓名',
    `mobile` varchar(32) not null comment '手机号',
    `email` varchar(64) not null comment '邮箱',
    `password` varchar(64) not null comment '密码',
    `gender` tinyint(4) comment '性别 1-男 2-女',
    `avatar` varchar(255) comment '头像相对地址',
    `is_use` tinyint(4) not null comment '账号是否启用 1-启用 0-禁用',
    `creator` bigint not null comment '创建人id',
    `creator_name` varchar(255) not null comment '创建人名称',
    `create_time` datetime not null default current_timestamp comment '创建时间',
    `modifier` bigint not null comment '修改人id',
    `modifier_name` varchar(255) not null comment '修改人名称',
    `modify_time` datetime not null comment '修改时间',
    `last_login_time` datetime comment '最后一次登录系统时间',
    `last_login_ip` varchar(64) comment '最后一次登录系统ip',
    `last_mod_pwd_time` datetime comment '最后一次修改密码时间',
    primary key (`id`),
    unique key `idx_mobile` (`mobile`),
    unique key `idx_email` (`email`)
) engine=innodb default charset=utf8mb4 comment='用户表';

create table `b_role` (
    `id` bigint unsigned not null auto_increment comment '唯一标识',
    `name` varchar(32) not null comment '名称',
    `is_use` tinyint(4) not null comment '启用/禁用 1-启用, 0-禁用',
    `creator` bigint not null comment '创建人',
    `creator_name` varchar(255) not null comment '创建人名称',
    `create_time` datetime not null default current_timestamp comment '创建时间',
    `remark` varchar(255) comment '备注',
    primary key (`id`)
) engine=innodb default charset=utf8mb4 comment='角色表';

create table `b_menu` (
    `id` bigint unsigned not null auto_increment comment '唯一标识',
    `name` varchar(255) not null comment '名称',
    `parent_id` bigint not null comment '父菜单 id 如果是一级菜单, 那么值为 0',
    `url` varchar(255) comment 'url',
    `type` tinyint(4) not null comment '菜单类型, 1-目录, 2-菜单',
    `is_use` tinyint(4) not null comment '启用/禁用 1-启用, 0-禁用',
    `sort` int(11) not null comment '排序, 默认0',
    `creator` bigint not null comment '创建人',
    `creator_name` varchar(255) not null comment '创建人名称',
    `create_time` datetime not null default current_timestamp comment '创建时间',
    `remark` varchar(255) comment '备注',
    `label` varchar(255) comment '菜单标记 (英文), 全局唯一, 不可重复',
    `icon` varchar(50) comment '目录图标, type=1 时必填',
    primary key (`id`)
) engine=innodb default charset=utf8mb4 comment='菜单表';

create table `b_user_role` (
    `id` bigint unsigned not null auto_increment comment '唯一标识',
    `user_id` bigint not null comment '用户 id',
    `role_id` bigint not null comment '角色 id 如果是在子系统中授权的, 那么角色 id 在此处为空',
    `role_name` varchar(255) default null comment '角色名称 如果是在子系统中授权的, 那么角色名称在此处为空',
    `creator` bigint not null comment '创建人id',
    `creator_name` varchar(255) not null comment '创建人名称',
    `create_time` datetime not null default current_timestamp comment '创建时间',
    primary key (`id`)
) engine=innodb default charset=utf8mb4 comment=' 用户在业务系统的角色关联表';

create table `b_role_menu` (
    `id` bigint unsigned not null auto_increment comment '唯一标识',
    `menu_id` bigint not null comment '菜单 id',
    `role_id` bigint not null comment '角色 id',
    `creator` bigint not null comment '创建人',
    `creator_name` varchar(255) not null comment '创建人名称',
    `create_time` datetime not null default current_timestamp comment '创建时间',
    primary key (`id`)
) engine=innodb default charset=utf8mb4 comment='角色关联菜单表';
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值