SET NAMES utf8mb4;
SET
FOREIGN_KEY_CHECKS = 0;

DROP TABLE IF EXISTS `sys_menu`;
CREATE TABLE `sys_menu`
(
    `id`        bigint(20) NOT NULL AUTO_INCREMENT,
    `parent_id` bigint(20) NULL DEFAULT NULL COMMENT '父菜单ID，一级菜单为0',
    `name`      varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
    `path`      varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '菜单URL',
    `perms`     varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '授权(多个用逗号分隔，如：user:list,user:create)',
    `component` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
    `type`      int(5) NOT NULL COMMENT '类型     0：目录   1：菜单   2：按钮',
    `icon`      varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '菜单图标',
    `orderNum`  int(11) NULL DEFAULT NULL COMMENT '排序',
    `created`   datetime                                               NOT NULL,
    `updated`   datetime NULL DEFAULT NULL,
    `statu`     int(5) NOT NULL,
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `name`(`name`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 24 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic COMMENT '菜单表';

INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (1, 0, '系统管理', '', 'sys:manage', '', 0, 'el-icon-s-operation', 1, '2021-01-15 18:58:18', '2022-01-19 23:03:35',
        1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (2, 1, '用户管理', '/sys/users', 'sys:user:list', 'sys/User', 1, 'el-icon-s-custom', 1, '2021-01-15 19:03:45',
        '2022-04-09 03:35:14', 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (3, 1, '角色管理', '/sys/roles', 'sys:role:list', 'sys/Role', 1, 'el-icon-rank', 2, '2021-01-15 19:03:45',
        '2021-01-15 19:03:48', 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (4, 1, '菜单管理', '/sys/menus', 'sys:menu:list', 'sys/Menu', 1, 'el-icon-menu', 3, '2021-01-15 19:03:45',
        '2021-01-15 19:03:48', 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (7, 3, '添加角色', '', 'sys:role:save', '', 2, '', 1, '2021-01-15 23:02:25', '2022-04-09 03:18:40', 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (9, 2, '添加用户', NULL, 'sys:user:save', NULL, 2, NULL, 1, '2021-01-17 21:48:32', NULL, 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (10, 2, '修改用户', NULL, 'sys:user:update', NULL, 2, NULL, 2, '2021-01-17 21:49:03', '2021-01-17 21:53:04', 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (11, 2, '删除用户', NULL, 'sys:user:delete', NULL, 2, NULL, 3, '2021-01-17 21:49:21', NULL, 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (12, 2, '分配角色', NULL, 'sys:user:role', NULL, 2, NULL, 4, '2021-01-17 21:49:58', NULL, 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (13, 2, '重置密码', NULL, 'sys:user:repass', NULL, 2, NULL, 5, '2021-01-17 21:50:36', NULL, 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (14, 3, '修改角色', NULL, 'sys:role:update', NULL, 2, NULL, 2, '2021-01-17 21:51:14', NULL, 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (15, 3, '删除角色', NULL, 'sys:role:delete', NULL, 2, NULL, 3, '2021-01-17 21:51:39', NULL, 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (16, 3, '分配权限', NULL, 'sys:role:perm', NULL, 2, NULL, 5, '2021-01-17 21:52:02', '2022-01-19 21:38:53', 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (17, 4, '添加菜单', NULL, 'sys:menu:save', NULL, 2, NULL, 1, '2021-01-17 21:53:53', '2021-01-17 21:55:28', 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (18, 4, '修改菜单', NULL, 'sys:menu:update', NULL, 2, NULL, 2, '2021-01-17 21:56:12', '2022-01-19 21:18:49', 1);
INSERT INTO `light_application_db`.`sys_menu` (`id`, `parent_id`, `name`, `path`, `perms`, `component`, `type`, `icon`,
                                               `orderNum`, `created`, `updated`, `statu`)
VALUES (19, 4, '删除菜单', NULL, 'sys:menu:delete', NULL, 2, NULL, 3, '2021-01-17 21:56:36', NULL, 1);


DROP TABLE IF EXISTS `sys_role`;
CREATE TABLE `sys_role`
(
    `id`      bigint(20) NOT NULL AUTO_INCREMENT,
    `name`    varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '角色名称',
    `code`    varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '角色编码',
    `remark`  varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
    `created` datetime NULL DEFAULT NULL,
    `updated` datetime NULL DEFAULT NULL,
    `statu`   int(5) NOT NULL,
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `name`(`name`) USING BTREE,
    UNIQUE INDEX `code`(`code`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic COMMENT '角色表';

INSERT INTO `light_application_db`.`sys_role` (`id`, `name`, `code`, `remark`, `created`, `updated`, `statu`)
VALUES (2, '工作人员', 'WORKING_PERSONNEL', '只有基本查看功能', '2021-01-04 10:09:14', '2022-04-09 03:14:07', 1);
INSERT INTO `light_application_db`.`sys_role` (`id`, `name`, `code`, `remark`, `created`, `updated`, `statu`)
VALUES (1, '超级管理员', 'ADMIN', '系统默认最高权限，不可以编辑和任意修改', '2021-01-16 13:29:03', '2022-04-09 02:37:43', 1);

DROP TABLE IF EXISTS `sys_role_menu`;
CREATE TABLE `sys_role_menu`
(
    `id`      bigint(20) NOT NULL AUTO_INCREMENT,
    `role_id` bigint(20) NOT NULL,
    `menu_id` bigint(20) NOT NULL,
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 162 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic COMMENT '角色&菜单关联表';

INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (1, 1, 1);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (2, 1, 2);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (3, 1, 9);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (4, 1, 10);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (5, 1, 11);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (6, 1, 12);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (7, 1, 13);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (8, 1, 3);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (9, 1, 7);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (10, 1, 14);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (11, 1, 15);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (12, 1, 16);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (13, 1, 4);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (14, 1, 17);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (15, 1, 18);
INSERT INTO `light_application_db`.`sys_role_menu` (`id`, `role_id`, `menu_id`)
VALUES (16, 1, 19);


DROP TABLE IF EXISTS `sys_user`;
CREATE TABLE `sys_user`
(
    `id`            bigint(20) NOT NULL AUTO_INCREMENT,
    `username`      varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户名称(登录账号)',
    `username_show` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户名称(显示名称)',
    `password`      varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '密码',
    `avatar`        varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '系统头像',
    `email`         varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '邮箱',
    `created`       datetime NULL DEFAULT NULL,
    `updated`       datetime NULL DEFAULT NULL,
    `last_login`    datetime NULL DEFAULT NULL COMMENT '上次登录时间',
    `statu`         int(5) NOT NULL,
    `phone`         varchar(16)   DEFAULT NULL COMMENT '手机号',
    `open_id`       varchar(256)  DEFAULT NULL COMMENT '普通用户的标识，对当前开发者帐号唯一',
    `nick_name`     varchar(256)  DEFAULT NULL COMMENT '普通用户昵称',
    `sex`           varchar(8)    DEFAULT NULL COMMENT '普通用户性别，1为男性，2为女性',
    `province`      varchar(256)  DEFAULT NULL COMMENT '普通用户个人资料填写的省份',
    `city`          varchar(256)  DEFAULT NULL COMMENT '普通用户个人资料填写的城市',
    `country`       varchar(256)  DEFAULT NULL COMMENT '国家，如中国为CN',
    `head_img_url`  varchar(1024) DEFAULT NULL COMMENT '用户头像，最后一个数值代表正方形头像大小（有0、46、64、96、132数值可选，0代表640*640正方形头像），用户没有头像时该项为空',
    `union_id`      varchar(256)  DEFAULT NULL COMMENT '用户统一标识。针对一个微信开放平台帐号下的应用，同一用户的unionid是唯一的。',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE INDEX `UK_USERNAME`(`username`) USING BTREE,
    UNIQUE INDEX `PHONE`(`phone`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic COMMENT '用户表';

INSERT INTO `light_application_db`.`sys_user` (`id`, `username`, `password`, `avatar`, `email`, `city`, `created`,
                                               `updated`, `last_login`, `statu`)
VALUES (1, 'admin', '$2a$10$yc0TxjbAanMGJuoJ6ItI2OjcTn2U10GHsmOW7HLNQcLpf5ulbXDLq',
        'https://blog20211013.oss-cn-shenzhen.aliyuncs.com/%E6%9C%BA%E5%99%A8%E4%BA%BA.png?versionId=CAEQMxiBgIC1geHI8xciIGI3NDY5NjRiMjExYTQxMmI5NTRlN2FlZGE4Yjc0ZTAx',
        '1231@qq.com', '广州', '2021-01-12 22:13:53', '2022-04-09 02:32:20', '2020-12-30 08:38:37', 1);
INSERT INTO `light_application_db`.`sys_user` (`id`, `username`, `password`, `avatar`, `email`, `city`, `created`,
                                               `updated`, `last_login`, `statu`)
VALUES (2, 'test', '$2a$10$ip1K.fCDAWOQVJO0kqgvGO32Vj.ferpGZWndbTO928m8vEYm4cBvq',
        'https://blog20211013.oss-cn-shenzhen.aliyuncs.com/%E6%9C%BA%E5%99%A8%E4%BA%BA%20(1).png?versionId=CAEQMxiBgIC5geHI8xciIGMxYjNlYWRhNTBmMzQxZTlhM2VhOTAxMTI3ODI1ZjM4',
        '953071241@qq.com', NULL, '2022-04-09 01:34:19', '2022-04-09 02:38:06', NULL, 1);

DROP TABLE IF EXISTS `sys_user_role`;
CREATE TABLE `sys_user_role`
(
    `id`      bigint(20) NOT NULL AUTO_INCREMENT,
    `user_id` bigint(20) NOT NULL,
    `role_id` bigint(20) NOT NULL,
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 25 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic COMMENT '用户&角色关联表';

INSERT INTO `light_application_db`.`sys_user_role` (`id`, `user_id`, `role_id`)
VALUES (1, 1, 1);
INSERT INTO `light_application_db`.`sys_user_role` (`id`, `user_id`, `role_id`)
VALUES (2, 2, 2);


SET
FOREIGN_KEY_CHECKS = 1;
