# live_operator_init
CREATE DATABASE IF NOT EXISTS `cmii_live_operator`;
USE `cmii_live_operator`;

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for live_gb_catalog
-- ----------------------------
DROP TABLE IF EXISTS `live_gb_catalog`;
CREATE TABLE `live_gb_catalog`  (
                                    `id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT 'id',
                                    `scope_id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'scope id',
                                    `create_scope_id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'create scope id',
                                    `device_id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'wvp device_id',
                                    `type` tinyint(1) NULL DEFAULT NULL COMMENT 'region or group',
                                    `parent_id` bigint(0) NULL DEFAULT NULL COMMENT 'sys parent catalog',
                                    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for live_gb_parent_platform
-- ----------------------------
DROP TABLE IF EXISTS `live_gb_parent_platform`;
CREATE TABLE `live_gb_parent_platform`  (
                                            `id` bigint(0) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id',
                                            `platform_id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'parentId',
                                            `scope_id` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'company scope permission id',
                                            `shared` tinyint(1) NULL DEFAULT 0 COMMENT 'is read',
                                            PRIMARY KEY (`id`) USING BTREE,
                                            UNIQUE INDEX `id`(`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for live_gb_sub_platform
-- ----------------------------
DROP TABLE IF EXISTS `live_gb_sub_platform`;
CREATE TABLE `live_gb_sub_platform`  (
                                         `platform_id` int(0) NOT NULL AUTO_INCREMENT,
                                         `platform_name` varchar(96) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                         `platform_gb_id` char(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                         `platform_gb_domain` char(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                         `platform_ip` varchar(96) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                         `platform_port_sip` int(0) NOT NULL,
                                         `platform_port_rtmp` int(0) NOT NULL,
                                         `platform_port_rtsp` int(0) NULL DEFAULT NULL,
                                         `platform_port_srt` int(0) NULL DEFAULT NULL,
                                         `platform_port_http` int(0) NULL DEFAULT NULL,
                                         `use_https` tinyint(1) NULL DEFAULT NULL,
                                         `platform_secret` varchar(96) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                         `company_id` int(0) NOT NULL,
                                         `shared` tinyint(1) NULL DEFAULT 0,
                                         PRIMARY KEY (`platform_id`) USING BTREE,
                                         UNIQUE INDEX `uniq_gb_id`(`platform_gb_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for live_hub
-- ----------------------------
DROP TABLE IF EXISTS `live_hub`;
CREATE TABLE `live_hub`  (
                             `id` int(0) NOT NULL AUTO_INCREMENT,
                             `hub` varchar(48) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                             `dvr` int(0) NOT NULL DEFAULT 0 COMMENT 'days for reserve, 0  for disable',
                             `pub` tinyint(0) NOT NULL DEFAULT 1 COMMENT '0: private; 1: pub play only; 2 pub push only; 3: pub all',
                             `active` tinyint(0) NOT NULL DEFAULT 1 COMMENT '1 yes, 0 no',
                             PRIMARY KEY (`id`) USING BTREE,
                             UNIQUE INDEX `uniq_hub`(`hub`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for live_platform_proxy
-- ----------------------------
DROP TABLE IF EXISTS `live_platform_proxy`;
CREATE TABLE `live_platform_proxy`  (
                                        `platform_id` int(0) NOT NULL AUTO_INCREMENT,
                                        `platform_name` varchar(96) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                        `platform_gb_id` char(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                        `platform_gb_domain` char(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                        `platform_ip` varchar(96) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                        `platform_port_sip` int(0) NOT NULL,
                                        `platform_port_rtmp` int(0) NOT NULL,
                                        `platform_port_rtsp` int(0) NULL DEFAULT NULL,
                                        `platform_port_srt` int(0) NULL DEFAULT NULL,
                                        `platform_port_http` int(0) NULL DEFAULT NULL,
                                        `use_https` tinyint(1) NULL DEFAULT NULL,
                                        `platform_secret` varchar(96) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                        `scope_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
                                        `shared` tinyint(1) NULL DEFAULT 0,
                                        `type` tinyint(1) NULL DEFAULT NULL,
                                        PRIMARY KEY (`platform_id`) USING BTREE,
                                        UNIQUE INDEX `uniq_gb_id`(`platform_gb_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for live_record
-- ----------------------------
DROP TABLE IF EXISTS `live_record`;
CREATE TABLE `live_record`  (
                                `id`               int(0)       NOT NULL AUTO_INCREMENT,
                                `record_uuid`      CHAR(32)     NOT NULL COMMENT '业务对外唯一ID，UUID32字符串',
                                `hub`              varchar(48)  NOT NULL,
                                `stream`           varchar(128) NOT NULL,
                                `time_begin`       datetime(3)  NOT NULL,
                                `time_end`         datetime(3)      NULL DEFAULT NULL,
                                `size`             bigint(0)    NOT NULL,
                                `status`           tinyint(0)   NOT NULL COMMENT '0-ok; 1-trash; 2-deleted; 3-live(完成部分上传，本段记录还未结束，仍在直播中); 4-init(上传首个切片)',
                                `thumbnail_uuid`   CHAR(32)         NULL DEFAULT NULL,
                                `thumbnail_bucket` varchar(48)      NULL DEFAULT NULL,
                                `thumbnail_path`   varchar(128)     NULL DEFAULT NULL,
                                PRIMARY KEY (`id`),
                                UNIQUE  INDEX `uniq_record_uuid`       (`record_uuid`),
                                UNIQUE  INDEX `uniq_hub_stream_time`   (`hub`, `stream`, `time_begin`),
                                INDEX `idx_hub_stream_status`  (`hub`, `stream`, `status`, `time_begin`),
                                INDEX `idx_time_begin`         (`time_begin`)
) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for live_segment
-- ----------------------------
DROP TABLE IF EXISTS `live_segment`;
CREATE TABLE `live_segment`  (
                                 `id`          bigint(0)     NOT NULL AUTO_INCREMENT,
                                 `file_uuid`   CHAR(32)      NOT NULL,
                                 `size`        bigint(0)     NOT NULL,
                                 `time_begin`  datetime(3)   NOT NULL,
                                 `time_end`    datetime(3)   NOT NULL,
                                 `status`      tinyint(0)    NOT NULL COMMENT '0-ok; 1-trash; 2-deleted; 3-uploading',
                                 `hub`         varchar(48)   NOT NULL,
                                 `stream`      varchar(128)  NOT NULL,
                                 `type`        varchar(12)   NOT NULL,
                                 `bucket`      varchar(32)   NOT NULL,
                                 `filename`    varchar(128)  NOT NULL,
                                 `record_uuid` CHAR(32)      NOT NULL COMMENT '推流记录id',
                                 PRIMARY KEY (`id`),
                                 UNIQUE  INDEX `uniq_file_uuid`         (`file_uuid`),
                                 UNIQUE  INDEX `uniq_hub_stream_time`   (`hub`, `stream`, `time_begin`),
                                 INDEX `idx_hub_stream_status`  (`hub`, `stream`, `status`, `time_begin`),
                                 INDEX `idx_time_begin`         (`time_begin`),
                                 INDEX `idx_record_uuid`        (`record_uuid`)
) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for live_stream
-- ----------------------------
DROP TABLE IF EXISTS `live_stream`;
CREATE TABLE `live_stream`  (
                                `id` char(8) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '0',
                                `hub` varchar(48) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                `stream` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
                                `dvr` int(0) NULL DEFAULT NULL COMMENT 'days for reserve, 0 for disable, null for inherit',
                                `pub` tinyint(0) NOT NULL DEFAULT 4 COMMENT '0: private; 1: pub play only; 2 pub push only; 3: pub all; 4: inherit',
                                `active` tinyint(0) NOT NULL DEFAULT 2 COMMENT '2 for inherit',
                                `activated_after` bigint(0) NULL DEFAULT NULL COMMENT 'sign effective time',
                                `metadata` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'business json',
                                `gb_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'gb_name',
                                `gb_enabled` tinyint(1) NULL DEFAULT NULL COMMENT '1 enabled ; 0 disabled',
                                `platform_proxy_id` bigint(0) NULL DEFAULT NULL COMMENT 'proxy id',
                                `scope_id` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'scope',
                                `gb_device_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'gb_id',
                                `stream_push_id` int(0) NULL DEFAULT NULL COMMENT 'stream push id',
                                `gb_id` int(0) NULL DEFAULT NULL COMMENT 'gb id',
                                `pushing` tinyint(1) NULL DEFAULT NULL COMMENT '1 true 0 false',
                                PRIMARY KEY (`id`) USING BTREE,
                                UNIQUE INDEX `uniq_stream`(`hub`, `stream`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for live_token
-- ----------------------------
DROP TABLE IF EXISTS `live_token`;
CREATE TABLE `live_token`  (
                               `id` int(0) NOT NULL AUTO_INCREMENT COMMENT 'id',
                               `access_key` varchar(12) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'ak',
                               `secret_key` varchar(24) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'sk',
                               `active` tinyint(1) NOT NULL DEFAULT 1 COMMENT '1 yes, 0 no',
                               PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for monitor_metric
-- ----------------------------
DROP TABLE IF EXISTS `monitor_metric`;
CREATE TABLE `monitor_metric`  (
                                   `id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '指标数据id',
                                   `metric_type` tinyint(1) NULL DEFAULT NULL COMMENT '指标类型',
                                   `data` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '指标值(存储的是字符串、可能是json)',
                                   `time` datetime(0) NULL DEFAULT NULL COMMENT '对应节点时间',
                                   `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '新增时间',
                                   PRIMARY KEY (`id`) USING BTREE,
                                   INDEX `idx_metric_time`(`metric_type`, `time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for live_config
-- ----------------------------
DROP TABLE IF EXISTS `live_config`;
CREATE TABLE `live_config` (
                               `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'id',
                               `k` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT 'key',
                               `v` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'value',
                               `prefix` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT 'name',
                               `remark` varchar(30) DEFAULT NULL COMMENT 'remark',
                               PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='配置表';

-- ----------------------------
-- live_hub data init
-- ----------------------------
INSERT INTO `live_hub`
VALUES (1, '__default_', 0, 1, 1);
INSERT INTO `live_hub`
VALUES (2, 'live', 60, 1, 1);
INSERT INTO `live_hub`
VALUES (3, 'temp', 0, 1, 1);
INSERT INTO `live_hub`
VALUES (4, 'pub', 0, 3, 1);

-- ----------------------------
-- live_token data init
-- ----------------------------
INSERT INTO `live_token`
VALUES (1, '2a4052005cee', '3d13c615112649e9b2e5f1f1', 1);

SET FOREIGN_KEY_CHECKS = 1;




