DROP TABLE IF EXISTS `wk_user`;
CREATE TABLE `wk_user`
(
    `id`              bigint(64)  NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
    `username`        VARCHAR(32) NOT NULL UNIQUE COMMENT '用户名',
    `nickname`        VARCHAR(32) NOT NULL UNIQUE COMMENT '昵称',
    `password`        VARCHAR(32) NOT NULL COMMENT '加密后的密码',
    `salt`            VARCHAR(32) NOT NULL COMMENT '加密使用的盐',
    `email`           VARCHAR(32) NOT NULL UNIQUE COMMENT '邮箱',
    `birthday`        DATETIME             DEFAULT NULL COMMENT '生日',
    `sex`             INT(2)               DEFAULT NULL COMMENT '性别,男-1,女-2',
    `phone`           VARCHAR(15)          DEFAULT NULL UNIQUE COMMENT '手机号',
    `status`          INT(2)      NOT NULL DEFAULT 1 COMMENT '状态 -1：删除 0：警用 1：启用',
    `create_time`     DATETIME    NOT NULL DEFAULT NOW() COMMENT '创建时间',
    `update_time`     DATETIME    NOT NULL DEFAULT NOW() COMMENT '上次更新时间',
    `last_login_time` DATETIME             DEFAULT NULL COMMENT '上次登录时间'
) ENGINE = INNODB
  DEFAULT CHARSET = UTF8 COMMENT '用户表';

DROP TABLE IF EXISTS `wk_role`;
CREATE TABLE `wk_role`
(
    `id`          BIGINT(64)  NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
    `name`        VARCHAR(32) NOT NULL UNIQUE COMMENT '角色名',
    `description` VARCHAR(100)         DEFAULT NULL COMMENT '描述',
    `create_time` DATETIME    NOT NULL DEFAULT NOW() COMMENT '创建时间',
    `update_time` DATETIME    NOT NULL DEFAULT NOW() COMMENT '更新时间'
) ENGINE = INNODB
  DEFAULT CHARSET = UTF8 COMMENT '角色表';

DROP TABLE IF EXISTS `wk_permission`;
CREATE TABLE `wk_permission`
(
    `id`         BIGINT(64)  NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
    `name`       VARCHAR(32) NOT NULL UNIQUE COMMENT '权限名',
    `url`        VARCHAR(1000) DEFAULT NULL COMMENT '类型为页面时,代表前端路由地址,类型为按钮时,代表后端接口地址',
    `type`       INT(2)      NOT NULL COMMENT '权限类型,页面-1,按钮-2',
    `permission` VARCHAR(50)   DEFAULT NULL COMMENT '权限表达式',
    `method`     VARCHAR(50)   DEFAULT NULL COMMENT '后端接口访问方式',
    `sort`       INT(11)     NOT NULL COMMENT '排序',
    `parent_id`  BIGINT(64)  NOT NULL COMMENT '父级ID'
) ENGINE = INNODB
  DEFAULT CHARSET = UTF8 COMMENT '权限表';

DROP TABLE IF EXISTS `wk_role_permission`;
CREATE TABLE `wk_role_permission`
(
    `role_id`       BIGINT(64) NOT NULL COMMENT '',
    `permission_id` BIGINT(64) NOT NULL COMMENT '',
    PRIMARY KEY (`role_id`, `permission_id`)
) ENGINE = INNODB
  DEFAULT CHARSET = UTF8 COMMENT '角色权限表';

DROP TABLE IF EXISTS `wk_role_user`;
CREATE TABLE `wk_role_user`
(
    `role_id` BIGINT(64) NOT NULL COMMENT '',
    `user_id` BIGINT(64) NOT NULL COMMENT '',
    PRIMARY KEY (`role_id`, `user_id`)
) ENGINE = INNODB
  DEFAULT CHARSET = UTF8 COMMENT '角色用户表';