drop table if exists skin_sequences;
create table skin_sequences(
    sequence_name  varchar(64)           not null,
    sequence_value integer               not null,
    primary key (sequence_name)
);

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)
);

drop table if exists skin_user;
create table skin_user(
    user_id                        integer primary key autoincrement,
    group_id                       integer              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,
    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,
    unique (user_name),
    unique (nick_name)
);

drop table if exists skin_user_session;
create table skin_user_session(
    id                   varchar(64) primary key 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
);

-- 角色表
drop table if exists skin_role;
create table skin_role(
    id                             integer primary key autoincrement,
    role_code                      varchar(64)          not null,
    role_name                      varchar(64)          not null,
    role_type                      tinyint(4)           not null,
    role_desc                      varchar(64)          not null,
    create_time                    datetime             not null,
    update_time                    datetime             not null
);

-- 权限表
drop table if exists skin_permission;
create table skin_permission(
    id                             integer primary key autoincrement,
    parent_id                      integer              not null,
    permission_key                 varchar(64)          not null,
    permission_name                varchar(128)         not null,
    permission_value               varchar(128)         not null,
    create_time                    datetime             not null,
    update_time                    datetime             not null,
    unique (permission_key)
);

-- 用户角色关系
drop table if exists skin_user_role;
create table skin_user_role(
    id                             integer primary key autoincrement,
    user_id                        integer              not null,
    role_id                        integer              not null,
    user_name                      varchar(64)          not null,
    role_name                      varchar(64)          not null,
    create_time                    datetime             not null,
    update_time                    datetime             not null,
    unique (user_id, role_id)
);

-- 角色权限
drop table if exists skin_role_permission;
create table skin_role_permission(
    id                             integer primary key autoincrement,
    role_id                        integer              not null,
    permission_id                  integer              not null,
    role_name                      varchar(64)          not null,
    permission_key                 varchar(64)          not null,
    permission_name                varchar(64)          not null,
    create_time                    datetime             not null,
    update_time                    datetime             not null,
    unique (role_id, permission_id)
);

drop table if exists skin_schedule;
create table skin_schedule(
    id               integer primary key autoincrement ,
    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
);

drop table if exists skin_schedule_log;
create table skin_schedule_log(
    id               integer primary key autoincrement,
    schedule_id      integer    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)
);

drop table if exists skin_access_log;
create table skin_access_log(
    id                             integer primary key autoincrement,
    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
);

