REPLACE INTO `authority_info` (`id`, `parent_id`, `name`, `remark`)
VALUES (1300, 0, 'app.key', 'AppKey管理'),
       (1301, 1300, 'app.key.find', '查询'),
       (1302, 1300, 'app.key.add', '添加'),
       (1303, 1300, 'app.key.edit', '修改'),
       (1304, 1300, 'app.key.disable', '禁用'),
       (1305, 1300, 'app.key.enable', '启用'),
       (1306, 1300, 'app.key.request.logs', '日志查询');

DROP TABLE IF EXISTS `app_key_info`;
CREATE TABLE `app_key_info`
(
    `id`           VARCHAR(32)  NOT NULL,
    `encrypt_key`  VARCHAR(64)  NOT NULL,
    `remark`       VARCHAR(100) NOT NULL DEFAULT '',
    `permissions`  TEXT         NULL     DEFAULT NULL,
    `is_enable`    INT(1)       NOT NULL,
    `created_time` DATETIME     NOT NULL,
    PRIMARY KEY (`id`),
    KEY `is_enable_index` (`is_enable`),
    KEY `created_time_index` (`created_time`)
) ENGINE = InnoDB;

DROP TABLE IF EXISTS `api_request_log`;
CREATE TABLE `api_request_log`
(
    `id`                 VARCHAR(32) NOT NULL,
    `app_key`            VARCHAR(20) NULL DEFAULT NULL,
    `method`             VARCHAR(50) NULL DEFAULT NULL,
    `version`            VARCHAR(50) NULL DEFAULT NULL,
    `request_body`       TEXT        NULL DEFAULT NULL,
    `response_data`      TEXT        NULL DEFAULT NULL,
    `client_ip`          VARCHAR(64) NOT NULL,
    `service_begin_time` DATETIME    NOT NULL,
    `service_end_time`   DATETIME    NOT NULL,
    PRIMARY KEY (`id`),
    KEY `app_key_index` (`app_key`),
    KEY `method_index` (`method`),
    KEY `version_index` (`version`),
    KEY `client_ip_index` (`client_ip`),
    KEY `service_begin_time_index` (`service_begin_time`)
) ENGINE = InnoDB;
