基本權限管理包含5張表。用戶表,角色表,用戶角色關聯表,權限表,權限角色關聯表。
1.用戶表數據庫
CREATE TABLE user ( id int NOT NULL AUTO_INCREMENT COMMENT 'ID', username varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用戶名', password varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密碼', nickname varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '暱稱', avatar varchar(255) DEFAULT NULL COMMENT '頭像', sex varchar(255) DEFAULT NULL COMMENT '性別', email varchar(255) DEFAULT NULL COMMENT '郵箱', phone varchar(255) DEFAULT NULL COMMENT '手機號碼', enabled tinyint(1) NOT NULL COMMENT '狀態:1啓用、0禁用', create_time datetime DEFAULT NULL COMMENT '建立日期', note varchar(255) DEFAULT NULL COMMENT '介紹', PRIMARY KEY (id) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='系統用戶';
2.角色表數據庫設計
CREATE TABLE `role` ( `id` int NOT NULL AUTO_INCREMENT, `name` varchar(64) DEFAULT NULL, `description` varchar(64) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
3.權限表ui
CREATE TABLE `menu` ( `id` int NOT NULL AUTO_INCREMENT, `icon` varchar(64) DEFAULT NULL, `name` varchar(64) DEFAULT NULL, `url` varchar(64) DEFAULT NULL, `pid` int DEFAULT NULL, `description` varchar(64) DEFAULT NULL, PRIMARY KEY (`id`), KEY `pid` (`pid`), CONSTRAINT `menu_ibfk_1` FOREIGN KEY (`pid`) REFERENCES `menu` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
4.用戶角色表url
CREATE TABLE `user_role` ( `id` int NOT NULL AUTO_INCREMENT, `userid` int DEFAULT NULL, `roleid` int DEFAULT NULL, PRIMARY KEY (`id`), KEY `userid` (`userid`), KEY `roleid` (`roleid`), CONSTRAINT `user_role_ibfk_1` FOREIGN KEY (`userid`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `user_role_ibfk_2` FOREIGN KEY (`roleid`) REFERENCES `role` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
5.權限角色表設計
CREATE TABLE `menu_role` ( `id` int NOT NULL AUTO_INCREMENT, `roleid` int DEFAULT NULL, `menuid` int DEFAULT NULL, PRIMARY KEY (`id`), KEY `roleid` (`roleid`), KEY `menuid` (`menuid`), CONSTRAINT `menu_role_ibfk_1` FOREIGN KEY (`roleid`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `menu_role_ibfk_2` FOREIGN KEY (`menuid`) REFERENCES `menu` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;