create table admin_auth
(
    id          int auto_increment
        primary key,
    env         varchar(255) default '' not null,
    parent_id   int                     null,
    type        int          default 0  not null comment '0:权限 1:路由菜单 2:按钮',
    hidden      int          default 0  not null comment '0:显示 1:隐藏',
    level       int          default 0  not null comment '层级，从1开始',
    `rank`      int          default 0  not null comment '排序，从小到大',
    name        varchar(255)            null comment '权限名称/路由组件名称/按钮编码',
    title       varchar(255)            null comment '显示的标题',
    icon        varchar(255)            null comment '显示的图标',
    path        varchar(1000)           null comment '链接的相对路径',
    link        varchar(1000)           null comment '链接的绝对路径',
    auths       varchar(1000)           null comment '拥有的权限编码，多个用逗号分隔',
    remark      varchar(255)            null comment '备注',
    create_time datetime                not null,
    update_time datetime                not null,
    status      int          default 0  not null
);

create table admin_env
(
    id          int auto_increment
        primary key,
    env         varchar(255)  not null,
    name        varchar(255)  not null,
    create_time datetime      not null,
    update_time datetime      not null,
    status      int default 0 not null
);

create table admin_role
(
    id          int auto_increment
        primary key,
    env         varchar(255) default '' not null,
    name        varchar(255)            not null,
    remark      varchar(255)            null,
    create_time datetime                not null,
    update_time datetime                not null,
    status      int          default 0  not null
);

create table admin_role_ref_auth
(
    id      int auto_increment
        primary key,
    env     varchar(255) not null,
    role_id int(20)      not null,
    auth_id int          not null
);

alter table admin_user
    add env varchar(255) default '' not null after id;

alter table admin_user
    add user_type int default 0 not null comment '0:普通用户 1:超级管理员' after env;

create table admin_user_ref_app
(
    id      int auto_increment
        primary key,
    user_id bigint       not null,
    app_id  int          not null,
    env     varchar(255) not null
);

create table admin_user_ref_role
(
    id      int auto_increment
        primary key,
    user_id bigint       not null,
    role_id int          not null,
    env     varchar(255) not null
);

create table app
(
    id           int auto_increment
        primary key,
    env          varchar(255) default '' not null,
    name         varchar(255)            not null,
    app_platform int                     not null,
    package_name varchar(255)            not null,
    remark       varchar(255)            null,
    create_time  datetime                not null,
    update_time  datetime                not null,
    status       int                     not null
);

alter table admin_auth
    drop column link;

alter table admin_auth
    add redirect varchar(1000) null comment '链接的绝对路径' after path;

alter table admin_auth
    add component varchar(1000) null comment '组件' after redirect;

alter table admin_auth
    change `rank` sort int default 0 not null comment '排序，从小到大';
