-- WebcatEE-1.2.5
drop table if exists webcat_database_driver;
create table webcat_database_driver(
    id                        bigint(20) auto_increment,
    driver_name               varchar(64)   not null,
    database_type             varchar(32)   not null,
    driver_class              varchar(128)  not null,
    version                   varchar(32)   not null,
    enabled                   int(10)       not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    unique key type_version(database_type, version)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_driver_file;
create table webcat_driver_file(
    id                        bigint(20) auto_increment,
    driver_id                 bigint(20)    not null,
    file_name                 varchar(64)   not null,
    file_path                 varchar(128)  not null,
    file_size                 bigint(20)    not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_database;
create table webcat_database(
    id                        bigint(20) auto_increment,
    server_id                 bigint(20)           not null,
    master_id                 bigint(20)           not null,
    database_name             varchar(64)          not null,
    database_type             varchar(32)          not null,
    database_env              varchar(16)          not null,
    node_type                 varchar(16)          not null,
    host                      varchar(64)          not null,
    port                      int(10)              not null,
    driver_id                 bigint(20)           not null,
    driver_class              varchar(256)         not null,
    url                       varchar(512)         not null,
    user_name                 varchar(64)          not null,
    password                  varchar(512)         not null,
    database_catalog          varchar(64)          not null,
    database_schema           varchar(64)          not null,
    database_tablespace       varchar(64)          not null,
    table_query_sql           varchar(2048),
    connection_properties     varchar(1024)        not null,
    query_timeout             int(10)              not null,
    query_interval            int(10)              not null,
    allow_query_rows          int(10)              not null,
    readonly                  int(10)    default 0 not null,
    enable                    int(10)    default 1 not null,
    version                   bigint(20) default 1 not null,
    create_time               datetime             not null,
    update_time               datetime             not null,
    primary key (id),
    unique key uk_database_name(database_name)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_database_owner;
create table webcat_database_owner(
    id                        bigint(20) auto_increment,
    owner_id                  bigint(20)   not null,
    owner_name                varchar(64)  not null,
    database_id               bigint(20)   not null,
    database_name             varchar(128) not null,
    role_name                 varchar(32)  not null,
    full_table                int(10)      not null,
    expire_days               int(10)      not null,
    expire_time               datetime     not null,
    display_order             int(10)      not null,
    create_time               datetime     not null,
    update_time               datetime     not null,
    primary key (id),
    unique key uk_owner_db(owner_id, database_id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_user_table;
create table webcat_user_table(
    id                        bigint(20) auto_increment,
    user_id                   bigint(20)   not null,
    user_name                 varchar(64)  not null,
    database_id               bigint(20)   not null,
    database_name             varchar(128) not null,
    table_name                varchar(32)  not null,
    expire_days               int(10)      not null,
    expire_time               datetime     not null,
    create_time               datetime     not null,
    update_time               datetime     not null,
    primary key (id),
    unique key uk_user_table(user_id, database_id, table_name)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_sensitive_field;
create table webcat_sensitive_field(
    id                        bigint(20) auto_increment,
    database_id               bigint(20)   not null,
    database_name             varchar(128) not null,
    table_name                varchar(64)  not null,
    column_name               varchar(64)  not null,
    display_pattern           varchar(64)  not null,
    properties                varchar(512) not null,
    create_time               datetime     not null,
    update_time               datetime     not null,
    primary key (id),
    unique key uk_table_column(database_id, table_name, column_name)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_query_log;
create table webcat_query_log(
    id                        bigint(20) auto_increment,
    user_id                   bigint(20)    not null,
    user_name                 varchar(64)   not null,
    database_id               bigint(20)    not null,
    database_name             varchar(128)  not null,
    database_type             varchar(32)   not null,
    database_env              varchar(128)  not null,
    node_name                 varchar(64)   not null,
    thread_name               varchar(64)   not null,
    remote_ip                 varchar(64)   not null,
    query_token               varchar(64)   not null,
    query_md5                 varchar(64)   not null,
    query_summary             varchar(1024) not null,
    query_sql                 mediumtext    not null,
    query_status              int(10)       not null,
    query_result              text,
    affected_rows             int(10)       not null,
    elapsed_time              bigint(20)    not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    key idx_user(user_id),
    key idx_database(database_id),
    key idx_token(query_token),
    key idx_md5(query_md5)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_attachment;
create table webcat_attachment(
    id                        bigint(20) auto_increment,
    user_id                   bigint(20)    not null,
    file_uuid                 varchar(64)   not null,
    file_name                 varchar(128)  not null,
    file_path                 varchar(128)  not null,
    file_size                 bigint(20)    not null,
    mime_type                 varchar(64)   not null,
    last_modified             bigint(20)    not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_data_file;
create table webcat_data_file(
    id                        bigint(20) auto_increment,
    user_id                   bigint(20)    not null,
    order_id                  bigint(20)    not null,
    database_id               bigint(20)    not null,
    file_uuid                 varchar(64)   not null,
    file_name                 varchar(128)  not null,
    file_path                 varchar(128)  not null,
    file_size                 bigint(20)    not null,
    mime_type                 varchar(64)   not null,
    last_modified             bigint(20)    not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_data_text;
create table webcat_data_text(
    id                        bigint(20) auto_increment,
    user_id                   bigint(20)    not null,
    order_id                  bigint(20)    not null,
    database_id               bigint(20)    not null,
    content_length            bigint(20)    not null,
    mime_type                 varchar(64)   not null,
    content                   text          not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_data_check;
create table webcat_data_check(
    id                        bigint(20) auto_increment,
    user_id                   bigint(20)    not null,
    order_id                  bigint(20)    not null,
    database_id               bigint(20)    not null,
    data_id                   bigint(20)    not null,
    data_type                 varchar(32)   not null,
    mime_type                 varchar(64)   not null,
    order_name                varchar(128)  not null,
    order_type                int(10)       not null,
    check_token               varchar(64)   not null,
    check_level               varchar(16)   not null,
    status                    int(10)       not null,
    result                    text          not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    key idx_user_id(user_id),
    key idx_order_id(order_id),
    key idx_db_id(database_id),
    unique key uk_data(data_id, data_type)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_order_execute;
create table webcat_order_execute(
    id                bigint(20) auto_increment,
    user_id           bigint(20)    not null,
    order_id          bigint(20)    not null,
    database_id       bigint(20)    not null,
    order_name        varchar(128)  not null,
    order_type        int(10)       not null,
    data_id           bigint(20)    not null,
    data_type         varchar(32)   not null,
    schedule_type     int(10)       not null,
    schedule_time     datetime      not null,
    execute_token     varchar(64)   not null,
    log_path          varchar(128)  not null,
    status            int(10)       not null,
    result            text          not null,
    create_time       datetime      not null,
    update_time       datetime      not null,
    primary key (id),
    key idx_user_id(user_id),
    key idx_order_id(order_id),
    key idx_db_id(database_id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_work_order;
create table webcat_work_order(
    id                bigint(20)  auto_increment not null,
    parent_id         bigint(20)                 not null,
    order_name        varchar(128)               not null,
    order_type        int(10)                    not null,
    user_id           bigint(20)                 not null,
    user_name         varchar(64)                not null,
    database_id       bigint(20)                 not null,
    database_name     varchar(64)                not null,
    database_env      varchar(32)                not null,
    order_data        text                       not null,
    audit_id          bigint(20)                 not null,
    audit_user_id     bigint(20)                 not null,
    audit_user_name   varchar(64)                not null,
    remarks           varchar(256)               not null,
    opinion           varchar(128)               not null,
    execute_status    int(10)                    not null,
    status            int(10)                    not null,
    create_time       datetime                   not null,
    update_time       datetime                   not null,
    primary key (id),
    key idx_user_id (user_id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_database_order;
create table webcat_database_order(
    id                bigint(20)    not null,
    parent_id         bigint(20)    not null,
    order_name        varchar(128)  not null,
    user_id           bigint(20)    not null,
    user_name         varchar(64)   not null,
    database_id       bigint(20)    not null,
    database_name     varchar(64)   not null,
    database_env      varchar(32)   not null,
    user_role         varchar(32)   not null,
    expire_days       int(10)       not null,
    audit_id          bigint(20)    not null,
    audit_user_id     bigint(20)    not null,
    audit_user_name   varchar(64)   not null,
    remarks           varchar(256)  not null,
    opinion           varchar(128)  not null,
    execute_status    int(10)       not null,
    status            int(10)       not null,
    create_time       datetime      not null,
    update_time       datetime      not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_table_order;
create table webcat_table_order(
    id                bigint(20)    not null,
    parent_id         bigint(20)    not null,
    order_name        varchar(128)  not null,
    user_id           bigint(20)    not null,
    user_name         varchar(64)   not null,
    database_id       bigint(20)    not null,
    database_name     varchar(64)   not null,
    database_env      varchar(32)   not null,
    tables            text          not null,
    expire_days       int(10)       not null,
    audit_id          bigint(20)    not null,
    audit_user_id     bigint(20)    not null,
    audit_user_name   varchar(64)   not null,
    remarks           varchar(256)  not null,
    opinion           varchar(128)  not null,
    execute_status    int(10)       not null,
    status            int(10)       not null,
    create_time       datetime      not null,
    update_time       datetime      not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_base_change_order;
create table webcat_base_change_order(
    id                    bigint(20)    not null,
    parent_id             bigint(20)    not null,
    order_name            varchar(128)  not null,
    user_id               bigint(20)    not null,
    user_name             varchar(64)   not null,
    database_id           bigint(20)    not null,
    database_name         varchar(64)   not null,
    database_env          varchar(32)   not null,
    data_id               bigint(20)    not null,
    data_type             varchar(32)   not null,
    affected_rows         int(10)       not null,
    schedule_type         int(10)       not null,
    schedule_time         datetime      not null,
    audit_id              bigint(20)    not null,
    audit_user_id         bigint(20)    not null,
    audit_user_name       varchar(64)   not null,
    execute_id            bigint(10)    not null,
    execute_status        int(10)       not null,
    remarks               varchar(256)  not null,
    opinion               varchar(128)  not null,
    status                int(10)       not null,
    create_time           datetime      not null,
    update_time           datetime      not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_data_change_order;
create table webcat_data_change_order(
    id                    bigint(20)    not null,
    parent_id             bigint(20)    not null,
    order_name            varchar(128)  not null,
    user_id               bigint(20)    not null,
    user_name             varchar(64)   not null,
    database_id           bigint(20)    not null,
    database_name         varchar(64)   not null,
    database_env          varchar(32)   not null,
    data_id               bigint(20)    not null,
    data_type             varchar(32)   not null,
    mime_type             varchar(32)   not null,
    rollback_data_id      bigint(20)    not null,
    rollback_data_type    varchar(32)   not null,
    batch_insert          int(10)       not null,
    change_options        varchar(1024) not null,
    affected_rows         int(10)       not null,
    schedule_type         int(10)       not null,
    schedule_time         datetime      not null,
    audit_id              bigint(20)    not null,
    audit_user_id         bigint(20)    not null,
    audit_user_name       varchar(64)   not null,
    execute_id            bigint(10)    not null,
    execute_status        int(10)       not null,
    remarks               varchar(256)  not null,
    opinion               varchar(128)  not null,
    status                int(10)       not null,
    create_time           datetime      not null,
    update_time           datetime      not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_data_export_order;
create table webcat_data_export_order(
    id                    bigint(20)    not null,
    parent_id             bigint(20)    not null,
    order_name            varchar(128)  not null,
    user_id               bigint(20)    not null,
    user_name             varchar(64)   not null,
    database_id           bigint(20)    not null,
    database_name         varchar(64)   not null,
    database_env          varchar(32)   not null,
    data_id               bigint(20)    not null,
    data_type             varchar(32)   not null,
    affected_rows         int(10)       not null,
    schedule_type         int(10)       not null,
    schedule_time         datetime      not null,
    audit_id              bigint(20)    not null,
    audit_user_id         bigint(20)    not null,
    audit_user_name       varchar(64)   not null,
    execute_id            bigint(10)    not null,
    execute_status        int(10)       not null,
    export_path           varchar(128)  not null,
    remarks               varchar(256)  not null,
    opinion               varchar(128)  not null,
    status                int(10)       not null,
    create_time           datetime      not null,
    update_time           datetime      not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_pending_work;
create table webcat_pending_work(
    id                bigint(20)  auto_increment not null,
    user_id           bigint(20)                 not null,
    database_id       bigint(20)                 not null,
    database_name     varchar(64)                not null,
    database_env      varchar(32)                not null,
    order_id          bigint(20)                 not null,
    order_name        varchar(128)               not null,
    order_type        int(10)                    not null,
    apply_user_id     bigint(20)                 not null,
    apply_user_name   varchar(64)                not null,
    opinion           varchar(128)               not null,
    execute_status    int(10)                    not null,
    status            int(10)                    not null,
    create_time       datetime                   not null,
    update_time       datetime                   not null,
    primary key (id),
    key idx_user_id(user_id),
    unique key uk_user_order(user_id, order_id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_order_log;
create table webcat_order_log(
    id                             bigint(20) auto_increment not null,
    order_id                       bigint(20)           not null,
    operator_id                    bigint(20)           not null,
    operator_name                  varchar(64)          not null,
    operation_type                 varchar(32)          not null,
    data_object                    varchar(2048)        not null,
    create_time                    datetime             not null,
    update_time                    datetime             not null,
    primary key (id),
    key idx_order_id(order_id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_order_job;
create table webcat_order_job(
    id                             bigint(20) auto_increment not null,
    database_id                    bigint(20)           not null,
    order_id                       bigint(20)           not null,
    order_name                     varchar(128)         not null,
    order_type                     int(10)              not null,
    user_id                        bigint(20)           not null,
    user_name                      varchar(64)          not null,
    action_type                    int(10)              not null,
    properties                     varchar(255)         not null,
    status                         int(10)              not null,
    fire_time                      bigint(20)           not null,
    create_time                    datetime             not null,
    update_time                    datetime             not null,
    primary key (id),
    unique key uk_biz_key(order_id, action_type)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_order_job_history;
create table webcat_order_job_history(
    id                             bigint(20) auto_increment not null,
    database_id                    bigint(20)           not null,
    order_id                       bigint(20)           not null,
    order_name                     varchar(128)         not null,
    order_type                     int(10)              not null,
    user_id                        bigint(20)           not null,
    user_name                      varchar(64)          not null,
    action_type                    int(10)              not null,
    properties                     varchar(255)         not null,
    status                         int(10)              not null,
    fire_time                      bigint(20)           not null,
    create_time                    datetime             not null,
    update_time                    datetime             not null,
    primary key (id),
    unique key uk_biz_key(order_id, action_type)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_execute_progress;
create table webcat_execute_progress(
    id                             bigint(20) auto_increment not null,
    user_id                        bigint(20)           not null,
    database_id                    bigint(20)           not null,
    token                          varchar(64)          not null,
    status                         int(10)              not null,
    message                        varchar(256)         not null,
    create_time                    datetime             not null,
    update_time                    datetime             not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_user_notify;
create table webcat_user_notify(
    id                   bigint(20) auto_increment,
    user_id              bigint(20)     not null,
    biz_id               bigint(20)     not null,
    biz_type             int(10)        not null,
    content              text           not null,
    readed               tinyint(1)     not null,
    deleted              tinyint(1)     not null,
    create_time          datetime       not null,
    update_time          datetime       not null,
    primary key (id),
    key idx_user_id (user_id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_profile;
create table webcat_profile(
    id               bigint(20)  auto_increment not null,
    name             varchar(64)                not null,
    content          text                       not null,
    create_time      datetime                   not null,
    update_time      datetime                   not null,
    primary key (id),
    unique key uk_name(name)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_mail_template;
create table webcat_mail_template(
    id               bigint(20)  auto_increment not null,
    name             varchar(128)               not null,
    content          text                       not null,
    create_time      datetime                   not null,
    update_time      datetime                   not null,
    primary key (id),
    unique key uk_name(name)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_monitor;
create table webcat_monitor(
    id                        bigint(20)  auto_increment not null,
    monitor_name              varchar(64)                not null,
    monitor_type              varchar(64)                not null,
    monitor_config            text                       not null,
    agent_name                varchar(64)                not null,
    agent_url                 varchar(256)               not null,
    shard_name                varchar(64)                not null,
    table_name                varchar(64)                not null,
    enabled                   tinyint(3)                 not null,
    status                    tinyint(3)                 not null,
    create_time               datetime                   not null,
    update_time               datetime                   not null,
    primary key (id),
    key idx_monitor_name(monitor_name),
    key idx_agent_name(agent_name)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_database_server;
create table webcat_database_server(
    id                        bigint(20)  auto_increment not null,
    server_name               varchar(64)                not null,
    server_host               varchar(64)                not null,
    server_port               int(10)                    not null,
    server_url                varchar(1024)              not null,
    database_type             varchar(32)                not null,
    database_env              varchar(32)                not null,
    driver_id                 bigint(20)                 not null,
    driver_class              varchar(256)               not null,
    user_name                 varchar(64)                not null,
    password                  varchar(512)               not null,
    properties                varchar(1024)              not null,
    agent_name                varchar(64)                not null,
    agent_url                 varchar(256)               not null,
    shard_name                varchar(64)                not null,
    table_name                varchar(64)                not null,
    enabled                   tinyint(3)                 not null,
    status                    tinyint(3)                 not null,
    create_time               datetime                   not null,
    update_time               datetime                   not null,
    primary key (id),
    key idx_server_name(server_name),
    key idx_agent_name(agent_name)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_mysql_status;
create table webcat_mysql_status(
    id                                            bigint(20) auto_increment not null,
    server_id                                     bigint(20)    default '0' not null,
    host                                          varchar(64)   default ''  not null,
    port                                          int(10)       default 0   not null,
    tags                                          varchar(64)   default ''  not null,
    uptime                                        int(10)       default 0   not null,
    aborted_clients                               int(10)       default 0   not null,
    aborted_connects                              int(10)       default 0   not null,
    max_connections                               int(10)       default 0   not null,
    max_connect_errors                            int(10)       default 0   not null,
    open_files_limit                              int(10)       default 0   not null,
    open_files                                    int(10)       default 0   not null,
    table_open_cache                              int(10)       default 0   not null,
    open_tables                                   int(10)       default 0   not null,
    max_tmp_tables                                int(10)       default 0   not null,
    max_heap_table_size                           int(10)       default 0   not null,
    max_allowed_packet                            int(10)       default 0   not null,
    threads_connected                             int(10)       default 0   not null,
    threads_running                               int(10)       default 0   not null,
    threads_waits                                 int(10)       default 0   not null,
    threads_created                               int(10)       default 0   not null,
    threads_cached                                int(10)       default 0   not null,
    connections                                   int(10)       default 0   not null,
    connections_per_second                        int(10)       default 0   not null,
    bytes_received_per_second                     bigint(20)    default '0' not null,
    bytes_sent_per_second                         bigint(20)    default '0' not null,
    com_select_per_second                         int(10)       default 0   not null,
    com_insert_per_second                         int(10)       default 0   not null,
    com_update_per_second                         int(10)       default 0   not null,
    com_delete_per_second                         int(10)       default 0   not null,
    com_commit_per_second                         int(10)       default 0   not null,
    com_rollback_per_second                       int(10)       default 0   not null,
    questions_per_second                          int(10)       default 0   not null,
    queries_per_second                            int(10)       default 0   not null,
    transaction_per_second                        int(10)       default 0   not null,
    created_tmp_tables_per_second                 int(10)       default 0   not null,
    created_tmp_disk_tables_per_second            int(10)       default 0   not null,
    created_tmp_files_per_second                  int(10)       default 0   not null,
    table_locks_immediate_per_second              int(10)       default 0   not null,
    table_locks_waited_per_second                 int(10)       default 0   not null,
    key_buffer_size                               bigint(20)    default '0' not null,
    sort_buffer_size                              int(10)       default 0   not null,
    join_buffer_size                              int(10)       default 0   not null,
    key_blocks_used                               int(10)       default 0   not null,
    key_blocks_unused                             int(10)       default 0   not null,
    key_blocks_not_flushed                        int(10)       default 0   not null,
    key_read_requests_per_second                  int(10)       default 0   not null,
    key_reads_per_second                          int(10)       default 0   not null,
    key_write_requests_per_second                 int(10)       default 0   not null,
    key_writes_per_second                         int(10)       default 0   not null,
    innodb_buffer_pool_instances                  int(10)       default 0   not null,
    innodb_buffer_pool_size                       bigint(20)    default 0   not null,
    innodb_doublewrite                            char(10)      default '0' not null,
    innodb_file_per_table                         char(10)      default '0' not null,
    innodb_flush_log_at_trx_commit                tinyint(2)    default 0   not null,
    innodb_flush_method                           varchar(30)   default '0' not null,
    innodb_force_recovery                         tinyint(2)    default 0   not null,
    innodb_io_capacity                            int(10)       default 0   not null,
    innodb_read_io_threads                        tinyint(2)    default 0   not null,
    innodb_write_io_threads                       tinyint(2)    default 0   not null,
    innodb_buffer_pool_pages_total                int(10)       default 0   not null,
    innodb_buffer_pool_pages_data                 int(10)       default 0   not null,
    innodb_buffer_pool_pages_dirty                int(10)       default 0   not null,
    innodb_buffer_pool_pages_flushed              bigint(20)    default 0   not null,
    innodb_buffer_pool_pages_free                 int(10)       default 0   not null,
    innodb_buffer_pool_pages_misc                 int(10)       default 0   not null,
    innodb_page_size                              int(10)       default 0   not null,
    innodb_pages_created                          bigint(20)    default 0   not null,
    innodb_pages_read                             bigint(20)    default 0   not null,
    innodb_pages_written                          bigint(20)    default 0   not null,
    innodb_row_lock_current_waits                 int(10)       default 0   not null,
    innodb_buffer_pool_pages_flushed_per_second   int(10)       default 0   not null,
    innodb_buffer_pool_read_requests_per_second   int(10)       default 0   not null,
    innodb_buffer_pool_reads_per_second           int(10)       default 0   not null,
    innodb_buffer_pool_write_requests_per_second  int(10)       default 0   not null,
    innodb_rows_read_per_second                   int(10)       default 0   not null,
    innodb_rows_inserted_per_second               int(10)       default 0   not null,
    innodb_rows_updated_per_second                int(10)       default 0   not null,
    innodb_rows_deleted_per_second                int(10)       default 0   not null,
    innodb_version                                varchar(30)   default ''  not null,
    query_cache_hit                               int(10)       default 0   not null,
    thread_cache_hit                              int(10)       default 0   not null,
    key_buffer_read_rate                          int(10)       default 0   not null,
    key_buffer_write_rate                         int(10)       default 0   not null,
    key_blocks_used_rate                          int(10)       default 0   not null,
    created_tmp_disk_tables_rate                  int(10)       default 0   not null,
    connections_usage                             int(10)       default 0   not null,
    open_files_usage                              int(10)       default 0   not null,
    open_tables_usage                             int(10)       default 0   not null,
    version                                       varchar(32)   default ''  not null,
    create_time                                   bigint(20)    default 0   not null,
    primary key (id),
    key idx_connections (threads_connected) using btree,
    key idx_active (threads_running) using btree,
    key idx_server_id (server_id) using btree,
    key idx_create_time (create_time) using btree
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_user_query;
create table webcat_user_query(
    id                        bigint(20) auto_increment,
    user_id                   bigint(20)    not null,
    user_name                 varchar(64)   not null,
    database_id               bigint(20)    not null,
    database_name             varchar(128)  not null,
    database_type             varchar(32)   not null,
    database_env              varchar(128)  not null,
    query_name                varchar(64)   not null,
    query_md5                 varchar(64)   not null,
    query_summary             varchar(1024) not null,
    query_sql                 mediumtext    not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    key idx_user(user_id),
    key idx_database(database_id),
    key idx_md5(query_md5)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_common_group;
create table webcat_common_group(
    id                        bigint(20) auto_increment,
    group_name                varchar(64)   not null,
    database_type             varchar(32)   not null,
    sys_enabled               tinyint(3)    not null,
    dba_enabled               tinyint(3)    not null,
    app_enabled               tinyint(3)    not null,
    dev_enabled               tinyint(3)    not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    key idx_db_type(database_type)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_common_sql;
create table webcat_common_sql(
    id                        bigint(20) auto_increment,
    group_id                  bigint(20)    not null,
    group_name                varchar(64)   not null,
    query_name                varchar(64)   not null,
    database_type             varchar(32)   not null,
    query_summary             varchar(1024) not null,
    query_sql                 mediumtext    not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    key idx_db_type(database_type)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_patch;
create table webcat_patch(
    id                        bigint(20) auto_increment,
    patch_code                varchar(64)   not null,
    patch_name                varchar(64)   not null,
    description               varchar(1024) not null,
    version                   varchar(32)   not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    unique key uk_code(patch_code),
    key idx_name(patch_name)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_system_log;
create table webcat_system_log(
    id                             bigint(20) auto_increment not null,
    local_ip                       varchar(64)         not null,
    thread_name                    varchar(64)         not null,
    level                          varchar(12)         not null,
    message                        varchar(1024)       not null,
    create_time                    datetime            not null,
    update_time                    datetime            not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_user_ip;
create table webcat_user_ip(
    id                             bigint(20) auto_increment not null,
    user_id                        bigint(20)          not null,
    user_name                      varchar(64)         not null,
    nick_name                      varchar(64)         not null,
    pattern                        varchar(64)         not null,
    ip_mode                        tinyint(4)          not null,
    remarks                        varchar(256)        not null,
    create_time                    datetime            not null,
    update_time                    datetime            not null,
    primary key (id),
    unique key uk_user_pattern(user_id, pattern)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_biz_query;
create table webcat_biz_query(
    id                        bigint(20) auto_increment,
    user_id                   bigint(20)    not null,
    user_name                 varchar(64)   not null,
    database_id               bigint(20)    not null,
    database_name             varchar(128)  not null,
    database_type             varchar(32)   not null,
    database_env              varchar(128)  not null,
    query_name                varchar(64)   not null,
    query_md5                 varchar(64)   not null,
    query_summary             varchar(1024) not null,
    query_sql                 mediumtext    not null,
    visibility                tinyint(4)    not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    key idx_user(user_id),
    key idx_database(database_id),
    key idx_md5(query_md5)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

-- @since 1.2.0
drop table if exists webcat_app_server;
create table webcat_app_server(
    id                        bigint(20) auto_increment,
    app_name                  varchar(64)   not null,
    node_name                 varchar(64)   not null,
    host                      varchar(64)   not null,
    port                      int(10)       not null,
    url                       varchar(128)  not null,
    token                     varchar(64)   not null,
    start_time                datetime      not null,
    heartbeat                 datetime      not null,
    register_time             datetime      not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    unique key uk_app_node(app_name, node_name)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_app_server_log;
create table webcat_app_server_log(
    id                        bigint(20) auto_increment,
    app_name                  varchar(64)   not null,
    node_name                 varchar(64)   not null,
    token                     varchar(64)   not null,
    start_time                datetime      not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    key idx_node_name(node_name)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_app_secret;
create table webcat_app_secret(
    id                        bigint(20) auto_increment,
    app_name                  varchar(64)   not null,
    public_key                varchar(2048) not null,
    private_key               varchar(2048) not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key(id),
    unique key uk_app_name(app_name)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_table_meta_data;
create table webcat_table_meta_data(
    id                        bigint(20) auto_increment,
    database_id               bigint(20)    not null,
    database_name             varchar(64)   not null,
    database_type             varchar(32)   not null,
    database_env              varchar(16)   not null,
    meta_data_schema          varchar(16)   not null,
    meta_data_value           varchar(64)   not null,
    table_catalog             varchar(64)       null,
    table_schema              varchar(64)       null,
    table_domain              varchar(64)   not null,
    table_type                varchar(16)   not null,
    table_name                varchar(64)   not null,
    column_name               varchar(64)   not null,
    data_type                 int(10)       not null,
    type_name                 varchar(64)   not null,
    column_size               int(10)           null,
    buffer_length             int(10)           null,
    decimal_digits            int(10)           null,
    num_prec_radix            int(10)           null,
    nullable                  int(10)           null,
    remarks                   varchar(256)      null,
    column_def                varchar(64)       null,
    sql_data_type             int(10)           null,
    sql_datetime_sub          int(10)           null,
    char_octet_length         int(10)           null,
    ordinal_position          int(10)           null,
    is_nullable               varchar(16)       null,
    scope_catalog             varchar(64)       null,
    scope_schema              varchar(64)       null,
    scope_table               varchar(64)       null,
    source_data_type          int(10)           null,
    is_autoincrement          varchar(16)       null,
    is_generatedcolumn        varchar(16)       null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    unique key uk_db_table_column(database_id, table_domain, table_name, column_name),
    key idx_database(database_id),
    key idx_value(meta_data_value)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_database_group;
create table webcat_database_group(
    id                        bigint(20) auto_increment,
    parent_id                 bigint(20)    not null,
    user_id                   bigint(20)    not null,
    group_name                varchar(64)   not null,
    display_order             int(10)       not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    key idx_user(user_id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_user_group_database;
create table webcat_user_group_database(
    id                        bigint(20) auto_increment,
    user_id                   bigint(20)    not null,
    group_id                  bigint(20)    not null,
    database_id               bigint(20)    not null,
    display_order             int(10)       not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    key idx_user(user_id),
    key idx_user_group(user_id, group_id),
    unique key uk_user_group_db(user_id, group_id, database_id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_meta_data_build_task;
create table webcat_meta_data_build_task(
    id                        bigint(20) auto_increment,
    user_id                   bigint(20)    not null,
    user_name                 varchar(64)   not null,
    database_id               bigint(20)    not null,
    database_name             varchar(64)   not null,
    database_type             varchar(32)   not null,
    database_env              varchar(16)   not null,
    node_name                 varchar(64)       null,
    build_time                datetime          null,
    elapsed_time              bigint(20)        null,
    status                    int(10)       not null,
    message                   text          not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    key idx_user(user_id),
    key idx_database(database_id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_meta_data_build_log;
create table webcat_meta_data_build_log(
    id                        bigint(20) auto_increment,
    task_id                   bigint(20)    not null,
    table_name                varchar(64)   not null,
    content                   text          not null,
    build_time                datetime      not null,
    create_time               datetime      not null,
    update_time               datetime      not null,
    primary key (id),
    key idx_task(task_id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_job_lock;
create table webcat_job_lock(
    lock_name varchar(64) not null,
    primary key (lock_name)
) engine=innodb default charset=utf8mb4;
insert into webcat_job_lock(lock_name) values ('meta_data_build_lock');

drop table if exists webcat_ssh_tunnel;
create table webcat_ssh_tunnel(
    id                        bigint(20) auto_increment,
    local_port                int(10)                 not null,
    remote_host               varchar(64)             not null,
    remote_port               int(10)                 not null,
    proxy_host                varchar(64)             not null,
    proxy_port                int(10)                 not null,
    auth_method               varchar(16)             not null,
    user_name                 varchar(64)             not null,
    password                  varchar(64)             not null,
    private_key               varchar(2048)           not null,
    passphrase                varchar(64)             not null,
    remarks                   varchar(256)            not null,
    enable                    int(10)                 not null,
    status                    int(10)                 not null,
    create_time               datetime                not null,
    update_time               datetime                not null,
    primary key (id),
    unique key uk_local_port(local_port)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

drop table if exists webcat_work_order_notify_log;
create table webcat_work_order_notify_log(
    id                        bigint(20) auto_increment,
    order_id                  bigint(20)              not null,
    auditor_id                bigint(20)              not null,
    local_host                varchar(64)             not null,
    thread_name               varchar(64)             not null,
    channel_name              varchar(64)             not null,
    code                      int(10)                 not null,
    message                   varchar(128),
    result                    text,
    create_time               datetime                not null,
    update_time               datetime                not null,
    primary key (id)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;

-- @since 1.2.9
drop table if exists webcat_user_profile;
create table webcat_user_profile(
    id               bigint(20)  auto_increment not null,
    user_id          bigint(20)                 not null,
    name             varchar(128)               not null,
    content          text                       not null,
    create_time      datetime                   not null,
    update_time      datetime                   not null,
    primary key (id),
    unique key uk_user_id_name(user_id, name)
) ENGINE=InnoDB default charset=utf8 collate=utf8_unicode_ci;
