SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

create table core_role_authority
(
    id          varchar(50)                not null
        primary key,
    create_time datetime                   not null,
    update_time datetime                   not null,
    is_deleted  int(6)      default 0      not null,
    service     varchar(50)                not null comment '服务',
    no          varchar(50)                not null comment '编号',
    name        varchar(50)                not null comment '名称',
    sort        int(6)      default 0      null comment '排序',
    level       int(6)      default 0      null comment '层级',
    parent      varchar(50)                null comment '父类ID',
    remark      varchar(500)               null comment '说明',
    is_open     int(6)      default 0      null comment '是否启用',
    type        varchar(20) default 'item' not null comment '类型：group-分组，menu-菜单项，point-点',
    link        text                       null comment '跳转地址',
    platform    varchar(20)                null comment '平台：ding、web、mobile等',
    ext1        varchar(500)               null comment '扩展1',
    ext2        varchar(500)               null comment '扩展2',
    ext3        varchar(500)               null comment '扩展3'
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
    comment '角色-权限';

create table core_role_group
(
    id          varchar(50)      not null
        primary key,
    create_time datetime         not null,
    update_time datetime         not null,
    is_deleted  int(6) default 0 not null,
    name        varchar(50)      not null comment '名称',
    remark      varchar(500)     null comment '说明',
    type        varchar(10)      null comment '类型：role-角色，job-职位',
    is_system   int(2) default 0 not null comment ' 是否系统',
    sort        int(6) default 0 not null comment '排序',
    ext1        varchar(500)     null comment '扩展1',
    ext2        varchar(500)     null comment '扩展2',
    ext3        varchar(500)     null comment '扩展3'
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
    comment '角色-分组';

create table core_role_group_rx
(
    id          varchar(50)      not null
        primary key,
    create_time datetime         not null,
    update_time datetime         not null,
    is_deleted  int(6) default 0 not null,
    group_id    varchar(50)      not null comment '角色id',
    menu_id     varchar(50)      not null comment '菜单id'
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
    comment '角色-分组-关系';

create table core_role_server
(
    id          varchar(50)      not null
        primary key,
    create_time datetime         not null,
    update_time datetime         not null,
    is_deleted  int(6) default 0 not null,
    name        varchar(255)     null comment '名称',
    remark      varchar(500)     null comment '说明',
    logo        varchar(500)     null comment 'logo',
    sort        int(6) default 0 null comment '排序',
    is_open     int(2) default 1 not null comment '是否启用',
    link        varchar(500)     null comment '跳转地址',
    ext1        varchar(500)     null comment '扩展1',
    ext2        varchar(500)     null comment '扩展2',
    ext3        varchar(500)     null comment '扩展3'
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
    comment '角色-服务';

create table core_role_user
(
    id          varchar(50)      not null
        primary key,
    create_time datetime         not null,
    update_time datetime         not null,
    is_deleted  int(6) default 0 not null,
    user_id     varchar(50)      not null comment '用户ID',
    type        varchar(50)      not null comment '类型：menu-菜单，job-职位',
    type_id     varchar(50)      not null comment '类型关联的记录ID',
    expire_time datetime         null comment '过期时间，无则不过期',
    ext1        varchar(500)     null comment '扩展1',
    ext2        varchar(500)     null comment '扩展2',
    ext3        varchar(500)     null comment '扩展3'
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
    comment '角色-用户';

alter table core_role_authority
    add version varchar(50) null comment '版本号' after platform;

alter table core_role_authority
    add source varchar(10) null comment '权限来源：auto-自动生成，input-添加' after version;

alter table core_role_authority
    add deps text null comment '依赖权限' after source;

alter table core_role_group_rx
    add type varchar(10) null comment '关联类型：dep-依赖，bind-绑定';

SET FOREIGN_KEY_CHECKS = 1;
