drop table if exists skin_sequences;
create table skin_sequences(
    sequence_name  varchar(64)           not null,
    sequence_value bigint(20)            not null,
    primary key (sequence_name)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci comment '自增序列';

drop table if exists skin_captcha;
create table skin_captcha(
    captcha_id      varchar(64)              not null,
    captcha_code    varchar(8)               not null,
    captcha_expiry  datetime                 not null,
    primary key (captcha_id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci comment '验证码';

drop table if exists skin_user;
create table skin_user(
    user_id                        bigint(20) auto_increment not null,
    group_id                       bigint(20)             not null,
    user_name                      varchar(64)            not null,
    nick_name                      varchar(64)            not null,
    user_mail                      varchar(64)            not null,
    mobile_phone                   varchar(32)            not null,
    weixin_open_id                 varchar(64) default '' not null,
    ding_user_id                   varchar(64) default '' not null,
    password                       varchar(64)            not null,
    user_salt                      varchar(128)           not null,
    secret_key                     varchar(20)            not null,
    user_level                     tinyint(4)             not null,
    user_gender                    tinyint(4)             not null,
    user_avatar                    varchar(200)           not null,
    user_signature                 varchar(250)           not null,
    create_time                    datetime               not null,
    update_time                    datetime               not null,
    expire_time                    datetime               not null,
    last_login_time                datetime,
    last_login_ip                  varchar(20),
    locked                         tinyint(4) default 0   not null,
    user_status                    tinyint(4)             not null,
    user_order                     int(11)                not null,
    primary key (user_id),
    unique key uk_user_name (user_name),
    unique key uk_nick_name (nick_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 comment '用户表';

drop table if exists skin_user_session;
create table skin_user_session(
    id                   varchar(64)         not null,
    app_id               bigint(20)          not null,
    user_id              bigint(20)          not null,
    user_name            varchar(32)         not null,
    nick_name            varchar(32)         not null,
    client_id            varchar(64)         not null,
    last_access_time     datetime            not null,
    create_time          datetime            not null,
    update_time          datetime            not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci comment '用户会话';

-- 角色表
drop table if exists skin_role;
create table skin_role(
    id                             bigint(20) auto_increment not null comment '主键',
    role_code                      varchar(64)          not null comment '角色代码',
    role_name                      varchar(64)          not null comment '角色名称',
    role_type                      tinyint(4)           not null comment '角色类型',
    role_desc                      varchar(64)          not null comment '角色描述',
    create_time                    datetime             not null comment '创建时间',
    update_time                    datetime             not null comment '更新时间',
    primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 comment '角色表';

-- 权限表
drop table if exists skin_permission;
create table skin_permission(
    id                             bigint(20) auto_increment not null comment '主键',
    parent_id                      bigint(20)           not null comment '父ID',
    permission_key                 varchar(64)          not null comment '权限key',
    permission_name                varchar(128)         not null comment '权限name',
    permission_value               varchar(128)         not null comment '权限value',
    create_time                    datetime             not null comment '创建时间',
    update_time                    datetime             not null comment '更新时间',
    primary key (id),
    unique key uk_key(permission_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 comment '权限';

-- 用户角色关系
drop table if exists skin_user_role;
create table skin_user_role(
    id                             bigint(20) auto_increment not null comment '主键',
    user_id                        bigint(20)           not null comment '用户ID',
    role_id                        bigint(20)           not null comment '角色ID',
    user_name                      varchar(64)          not null comment '用户名',
    role_name                      varchar(64)          not null comment '角色名',
    create_time                    datetime             not null comment '创建时间',
    update_time                    datetime             not null comment '更新时间',
    primary key (id),
    unique key uk_user_role(user_id, role_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 comment '用户角色关系';

-- 角色权限
drop table if exists skin_role_permission;
create table skin_role_permission(
    id                             bigint(20) auto_increment not null comment '主键',
    role_id                        bigint(20)           not null comment '角色ID',
    permission_id                  bigint(20)           not null comment '权限ID',
    role_name                      varchar(64)          not null comment '角色name',
    permission_key                 varchar(64)          not null comment '权限name',
    permission_name                varchar(64)          not null comment '权限name',
    create_time                    datetime             not null comment '创建时间',
    update_time                    datetime             not null comment '更新时间',
    primary key (id),
    unique key uk_role_permission(role_id, permission_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 comment '角色权限';

drop table if exists skin_schedule;
create table skin_schedule(
    id               bigint(20) auto_increment not null ,
    schedule_name    varchar(64)               not null,
    description      varchar(128)              not null,
    schedule_type    int(11)         default 0 not null,
    status           int(11)         default 0 not null,
    owner            varchar(64)               not null,
    expression       varchar(64),
    action           varchar(255)              not null,
    properties       text,
    last_fire_time   datetime,
    next_fire_time   datetime,
    execute_status   int(11)    default 0,
    execute_result   varchar(128),
    version          integer    default 0,
    create_time      datetime                  not null,
    update_time      datetime                  not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci comment '任务调度';

drop table if exists skin_schedule_log;
create table skin_schedule_log(
    id               bigint(20) not null auto_increment,
    schedule_id      bigint(20) not null,
    schedule_name    varchar(255) not null,
    schedule_type    int(11) default 0 not null,
    invocation       varchar(64) not null default 'auto',
    fire_time        datetime,
    next_fire_time   datetime,
    execute_status   int(11) default 0,
    execute_result   varchar(128),
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci comment '任务日志';

drop table if exists skin_access_log;
create table skin_access_log(
    id                             bigint(20) auto_increment not null,
    access_time                    datetime            not null,
    user_id                        int(11)             default 0 not null,
    user_name                      varchar(32),
    local_ip                       varchar(32),
    thread_name                    varchar(64),
    remote_host                    varchar(100)        not null,
    request_method                 varchar(12)         not null,
    request_protocol               varchar(12)         not null,
    request_url                    varchar(2560)       not null,
    request_referer                varchar(2560)       not null,
    client_id                      varchar(64)         not null,
    client_user_Agent              varchar(255)        not null,
    client_cookie                  varchar(2560)       not null,
    log_status                     int(10)             not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci comment '访问日志';
