CREATE DATABASE IF NOT EXISTS cmii_live_proxy;
use cmii_live_proxy;
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for proxy_task
-- ----------------------------
DROP TABLE IF EXISTS `proxy_task`;
CREATE TABLE `proxy_task`
(
    `id`             bigint(0)                                                     NOT NULL AUTO_INCREMENT COMMENT '任务id',
    `template_id`    bigint(0)                                                     NOT NULL COMMENT '关联模板',
    `name`           varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '任务名',
    `create_at`      datetime(0)                                                   NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
    `update_at`      datetime(0)                                                   NULL     DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间',
    `params`         varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '填充参数',
    `state`          tinyint(1)                                                    NOT NULL DEFAULT 1 COMMENT '执行状态\r\n(1、待定 2、执行中 3、异常 4、暂停)',
    `uuid`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  NOT NULL DEFAULT '123456' COMMENT '唯一标识(和process绑定)',
    `status`         tinyint(1)                                                    NOT NULL DEFAULT 1 COMMENT '状态',
    `execution_time` datetime(0)                                                   NULL     DEFAULT NULL COMMENT '执行时间',
    `sustain_time`   bigint(0)                                                     NULL     DEFAULT NULL COMMENT '持续时间',
    `retry_count`    int(0)                                                        NULL     DEFAULT 0 COMMENT '重试次数',
    `process_id`     varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  NULL     DEFAULT NULL COMMENT '进程id（最新）',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 8
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT = '任务表'
  ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for proxy_task_log
-- ----------------------------
DROP TABLE IF EXISTS `proxy_task_log`;
CREATE TABLE `proxy_task_log`
(
    `id`         bigint(0)                                                    NOT NULL AUTO_INCREMENT COMMENT '日志id',
    `content`    longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci    NULL COMMENT '日志',
    `task_id`    bigint(0)                                                    NULL     DEFAULT NULL COMMENT '任务id',
    `process_id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '进程id',
    `create_at`  datetime(0)                                                  NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
    `update_at`  datetime(0)                                                  NULL     DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间',
    `uuid`       longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci    NOT NULL COMMENT '唯一码',
    `is_new`     tinyint(1)                                                   NOT NULL COMMENT '是否最新进程',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 4076
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT = '任务日志表'
  ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for proxy_template
-- ----------------------------
DROP TABLE IF EXISTS `proxy_template`;
CREATE TABLE `proxy_template`
(
    `id`                bigint(0)                                                     NOT NULL AUTO_INCREMENT COMMENT '模板id',
    `create_at`         datetime(0)                                                   NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
    `update_at`         datetime(0)                                                   NULL     DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间',
    `ffmpeg_type`       tinyint(1)                                                    NOT NULL DEFAULT 1 COMMENT '执行类型：1 ffmpeg 2 ffprobe 3 ffplay',
    `command`           varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '模板数组',
    `name`              varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  NULL     DEFAULT NULL COMMENT '模板名称',
    `status`            tinyint(1)                                                    NULL     DEFAULT 1 COMMENT '状态',
    `placeholder_count` bigint(0)                                                     NULL     DEFAULT NULL COMMENT '占位参数个数',
    `operator_type`     tinyint(1)                                                    NULL     DEFAULT 1 COMMENT '执行类型：1 任务操作 2 文件操作',
    `alias`             varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '别名',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 10
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT = '模板表'
  ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for proxy_video_dest_file
-- ----------------------------
DROP TABLE IF EXISTS `proxy_video_dest_file`;
CREATE TABLE `proxy_video_dest_file`
(
    `id`            bigint(0)                                                     NOT NULL AUTO_INCREMENT COMMENT '转换文件',
    `create_at`     datetime(0)                                                   NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
    `update_at`     datetime(0)                                                   NULL     DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间',
    `template_id`   bigint(0)                                                     NULL     DEFAULT NULL COMMENT '模板id',
    `params`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '转换参数',
    `path`          varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '转换地址',
    `uri`           varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '文件uri',
    `url`           varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '文件url',
    `size`          bigint(0)                                                     NULL     DEFAULT NULL COMMENT '文件大小',
    `src_file_type` tinyint(1)                                                    NULL     DEFAULT NULL COMMENT '源文件选择类型(1 本地 2网络)',
    `src_file_id`   varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '源文件地址(如果为本地文件就是id)',
    `mime_type`     varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '文件转换扩展类型',
    `name`          varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '文件名',
    `state`         tinyint(1)                                                    NOT NULL DEFAULT 0 COMMENT '执行状态\r\n(1、待定 2、执行中 3、异常 4、结束)',
    `uuid`          varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '唯一码',
    `process_id`    varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  NULL     DEFAULT NULL COMMENT '进程id',
    `log`           longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci     NULL COMMENT '执行日志',
    `parent_path`   varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '父文件目录',
    `path_uuid`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  NULL     DEFAULT NULL COMMENT '父文件目录uuid',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 22
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT = '操作文件表'
  ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for proxy_video_src_file
-- ----------------------------
DROP TABLE IF EXISTS `proxy_video_src_file`;
CREATE TABLE `proxy_video_src_file`
(
    `id`        bigint(0)                                                     NOT NULL AUTO_INCREMENT COMMENT '文件id',
    `create_at` datetime(0)                                                   NOT NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
    `update_at` datetime(0)                                                   NULL     DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间',
    `name`      varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  NULL     DEFAULT NULL COMMENT '文件名',
    `uri`       varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '文件请求uri',
    `path`      varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '文件路径',
    `url`       varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '文件全路径url',
    `mime_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL     DEFAULT NULL COMMENT '文件类型',
    `size`      bigint(0)                                                     NULL     DEFAULT NULL COMMENT '文件大小',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 15
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT = '视频源文件表'
  ROW_FORMAT = Dynamic;

-- ----------------------------
-- proxy_template init data
-- ----------------------------
INSERT INTO `proxy_template` VALUES (1, '2026-03-30 15:11:59', '2026-03-30 15:12:50', 1, '-re -f lavfi -i testsrc=duration=86400:size=1280x720:rate=30 -c:v libx264 -preset ultrafast -tune zerolatency -profile baseline -g 30 -keyint_min 30 -sc_threshold 0 -pix_fmt yuv420p -f flv %s', '流媒体底座测试推流', 1, 1, 1, 'proxy_live_stream');

SET FOREIGN_KEY_CHECKS = 1;
