-- 初始化SQL for Mysql
-- tse_20.ts_cluster_node definition

CREATE TABLE `ts_cluster_node` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `ip` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'ip',
  `data` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '扩展数据',
  `port` int DEFAULT NULL COMMENT '端口号',
  `type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '类型',
  `last_heartbeat_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `idx_ipPort` (`ip`,`port`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;


-- tse_20.ts_dataset definition

CREATE TABLE `ts_dataset` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `dataset_guid` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '数据集id',
  `type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '类型 VDS，PDS',
  `partition_info` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '分区信息',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `delete_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '删除人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  `gmt_delete` timestamp NULL DEFAULT NULL COMMENT '删除时间',
  `is_delete` bit(1) DEFAULT NULL COMMENT '是否已删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_dataset_guid` (`dataset_guid`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='调度使用的数据集信息，主要是分区信息';


-- tse_20.ts_dataset_partition_instance definition

CREATE TABLE `ts_dataset_partition_instance` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `task_id` bigint unsigned DEFAULT '0' COMMENT '任务id',
  `guid` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '数据集id',
  `task_instance_id` bigint DEFAULT '0' COMMENT '任务实例',
  `partition_value` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '分区值',
  `partition_create_time` datetime DEFAULT NULL COMMENT '分区的创建时间',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_taskId_partition` (`task_id`,`partition_value`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='数据集分区实例\n';


-- tse_20.ts_datasource_config definition

CREATE TABLE `ts_datasource_config` (
  `id` bigint NOT NULL COMMENT '主键ID',
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `type` varchar(31) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `connection_url` varchar(511) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `properties` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;


-- tse_20.ts_reflection_dependency definition

CREATE TABLE `ts_reflection_dependency` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `tenant_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '租户id',
  `task_id` bigint unsigned DEFAULT '0' COMMENT '反射任务id',
  `reflection_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT 'rp_id',
  `dataset_guid` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '物理数据集 guid',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_reflectionId` (`reflection_id`) USING BTREE,
  KEY `idx_datasetGuid` (`dataset_guid`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='RP任务依赖';


-- tse_20.ts_reflection_task definition

CREATE TABLE `ts_reflection_task` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `task_id` bigint unsigned DEFAULT '0' COMMENT '反射任务id',
  `reflection_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '反射id',
  `dataset_guid` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '数据集 guid',
  `data` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '扩展数据',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `delete_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '删除人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  `gmt_delete` timestamp NULL DEFAULT NULL COMMENT '删除时间',
  `is_delete` bit(1) DEFAULT NULL COMMENT '是否已删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_taskId` (`task_id`) USING BTREE,
  KEY `idx_reflectionId` (`reflection_id`) USING BTREE,
  KEY `idx_guid` (`dataset_guid`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='反射任务';


-- tse_20.ts_resource_file definition

CREATE TABLE `ts_resource_file` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `tenant_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '租户id',
  `code` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '资源编发，租户下唯一',
  `name` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT 'jar名称',
  `description` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '描述',
  `versions` int NOT NULL COMMENT '版本id',
  `content_type` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '描述',
  `file_size` int DEFAULT '0' COMMENT '描述',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_tennantId_code` (`tenant_id`,`code`) USING BTREE COMMENT 'tenant ,code 唯一索引'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;


-- tse_20.ts_resource_file_fragment definition

CREATE TABLE `ts_resource_file_fragment` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `resource_file_id` bigint DEFAULT NULL COMMENT '资源id',
  `fragment_index` int DEFAULT NULL COMMENT '碎片序号',
  `content` longblob COMMENT '内容',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_fileId` (`resource_file_id`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;


-- tse_20.ts_resource_group definition

CREATE TABLE `ts_resource_group` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `tenant_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '租户id',
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '资源组名称',
  `description` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '资源组描述',
  `match_priority` int DEFAULT '0' COMMENT '规则匹配优先级',
  `rule_config` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '资源组规则配置',
  `schedule_config` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '资源组规则配置',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `delete_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '删除人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  `gmt_delete` timestamp NULL DEFAULT NULL COMMENT '删除时间',
  `is_delete` bit(1) DEFAULT NULL COMMENT '是否已删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_tenant` (`tenant_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='资源组定义表';


-- tse_20.ts_task definition

CREATE TABLE `ts_task` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `process_id` bigint NOT NULL DEFAULT '0' COMMENT '工作流id',
  `guid` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '数据集id',
  `tenant_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '租户id',
  `workspace_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '工作空间id',
  `type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '任务类型',
  `plugin_config` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '插件配置',
  `strategy_config` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '任务策略配置信息',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `delete_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '删除人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  `gmt_delete` timestamp NULL DEFAULT NULL COMMENT '删除时间',
  `is_delete` bit(1) DEFAULT NULL COMMENT '是否已删除',
  `data` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '扩展数据',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_tennantId_guid` (`tenant_id`,`guid`) USING BTREE COMMENT 'tenant ,guid 唯一索引',
  KEY `idx_guid` (`guid`) USING BTREE,
  KEY `idx_tenantId_workspaceId` (`tenant_id`,`workspace_id`) USING BTREE,
  KEY `idx_processId` (`process_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='任务定义表';


-- tse_20.ts_task_common_queue definition

CREATE TABLE `ts_task_common_queue` (
  `id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '主键ID',
  `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '队列名称',
  `trigger_time` bigint NOT NULL DEFAULT '20' COMMENT '触发时间',
  `message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '消息体',
  `flag` tinyint NOT NULL COMMENT '处理标记',
  `fetch_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '拉取编号',
  `fetch_time` datetime DEFAULT NULL COMMENT '拉取时间',
  `gmt_create` datetime NOT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_fetchId` (`fetch_id`) USING BTREE,
  KEY `idx_fetchTime` (`fetch_time`) USING BTREE,
  KEY `idx_queue_trigger_time` (`name`,`trigger_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='通用队列';


-- tse_20.ts_task_execution_context definition

CREATE TABLE `ts_task_execution_context` (
  `id` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '主键ID',
  `task_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '任务id',
  `parallel_no` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '并发编号',
  `process_instance_ids` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '进程ids',
  `task_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '任务类型',
  `server_ip` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '服务器ip',
  `trigger_time` datetime DEFAULT NULL COMMENT '触发时间',
  `last_check_time` datetime DEFAULT NULL COMMENT '最后校验时间',
  `params` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '执行参数',
  `options` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '执行选项',
  `task_instance_id` bigint DEFAULT '0' COMMENT '任务实例id',
  `process_task_type` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '工作流类型',
  `operator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '操作人',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_task_parallel` (`task_id`,`parallel_no`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;


-- tse_20.ts_task_instance definition

CREATE TABLE `ts_task_instance` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `tenant_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '租户id',
  `workspace_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '工作空间id',
  `ctx_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '执行上下文id',
  `process_id` bigint NOT NULL DEFAULT '0' COMMENT '工作流id',
  `task_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '任务id',
  `status` tinyint unsigned DEFAULT '0' COMMENT '任务状态  1-未执行 2-执行中 3执行成功 4-执行失败 5-暂停 6-停止 7-丢弃',
  `post_task_ids` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '进程ids',
  `process_instance_ids` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '进程ids',
  `retry_cnt` int unsigned DEFAULT '0' COMMENT '重试次数',
  `param` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '执行参数',
  `result` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '结果',
  `start_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '开始时间',
  `end_time` timestamp NULL DEFAULT NULL COMMENT '结束时间',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_taskId` (`task_id`) USING BTREE,
  KEY `idx_tenantId` (`tenant_id`) USING BTREE,
  KEY `idx_startTime` (`start_time`) USING BTREE,
  KEY `idx_gmtCreate` (`gmt_create`) USING BTREE,
  KEY `idx_processInstanceId` (`process_instance_ids`) USING BTREE,
  KEY `idx_processId` (`process_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='任务实例表';


-- tse_20.ts_task_lock definition

CREATE TABLE `ts_task_lock` (
  `lock_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '锁名称',
  PRIMARY KEY (`lock_name`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;

ALTER TABLE ts_task_lock ADD lock_owner varchar(255) NULL;
ALTER TABLE ts_task_lock ADD expire_date TIMESTAMP NULL;


-- tse_20.ts_task_period_instance definition

CREATE TABLE `ts_task_period_instance` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `task_id` bigint unsigned DEFAULT '0' COMMENT '任务id',
  `guid` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '数据集id',
  `task_instance_id` bigint DEFAULT '0' COMMENT '任务实例',
  `period` datetime NOT NULL COMMENT '分区值',
  `period_type` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '分区类型 HOUR , DAY, MONTH',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `param` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '周期参数',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_period` (`task_id`,`period`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='数据集分区实例';


-- tse_20.ts_task_pre_execution definition

CREATE TABLE `ts_task_pre_execution` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `task_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '任务id',
  `is_executing` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '是否执行中',
  `ctx_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '上下文id',
  `process_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '工作流id',
  `process_task_type` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '工作流类型',
  `params` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '执行参数',
  `gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
  `post_task_ids` varchar(511) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '下游任务',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_task_process` (`task_id`,`process_id`) USING BTREE,
  KEY `idx_process` (`process_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;


-- tse_20.ts_task_process definition

CREATE TABLE `ts_task_process` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `tenant_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '租户id',
  `workspace_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '工作空间id',
  `name` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '工作流名称',
  `status` tinyint unsigned DEFAULT '0' COMMENT '工作流状态 0 未上线 1-已上线',
  `data` text CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT '工作流数据',
  `plugin_config` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '插件配置',
  `strategy_config` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '任务策略配置信息',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `delete_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '删除人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  `gmt_delete` timestamp NULL DEFAULT NULL COMMENT '删除时间',
  `is_delete` bit(1) DEFAULT NULL COMMENT '是否已删除',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;


-- tse_20.ts_task_process_instance definition

CREATE TABLE `ts_task_process_instance` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `process_id` bigint NOT NULL DEFAULT '0' COMMENT '工作流id',
  `tenant_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '租户id',
  `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '触发备注',
  `start_task_id` bigint unsigned DEFAULT '0' COMMENT '任务id',
  `command_type` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '命令类型',
  `trigger_type` tinyint unsigned DEFAULT '0' COMMENT '触发类型 1 - 时间间隔调度 2 - CRON 3 - 事件触发 4 - 人工',
  `param` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '执行参数',
  `status` tinyint unsigned DEFAULT '0' COMMENT '任务状态  1-未执行 2-执行中 3执行成功 4-执行失败 5-暂停 6-停止 7-丢弃',
  `result` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '结果',
  `start_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '开始时间',
  `end_time` timestamp NULL DEFAULT NULL COMMENT '结束时间',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_startTaskId` (`start_task_id`) USING BTREE,
  KEY `idx_gmtCreate` (`gmt_create`) USING BTREE COMMENT '开始时间索引',
  KEY `idx_processId` (`process_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='任务工作流实例';


-- tse_20.ts_task_quartz_schedule definition

CREATE TABLE `ts_task_quartz_schedule` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `process_id` bigint NOT NULL DEFAULT '0' COMMENT '工作流id',
  `task_id` bigint unsigned DEFAULT '0',
  `type` tinyint DEFAULT NULL COMMENT '调度类型: 1 - 间隔调度 2 cron调度',
  `switch_flag` bit(1) DEFAULT b'1' COMMENT '开关  默认打开 ',
  `config` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '{}' COMMENT '配置',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `delete_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '删除人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  `gmt_delete` timestamp NULL DEFAULT NULL COMMENT '删除时间',
  `is_delete` bit(1) DEFAULT NULL COMMENT '是否已删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_taskId` (`task_id`) USING BTREE,
  KEY `idx_processId` (`process_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='任务定时配置';


-- tse_20.ts_task_quartz_trigger definition

CREATE TABLE `ts_task_quartz_trigger` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `task_id` bigint unsigned DEFAULT '0',
  `schedule_id` bigint unsigned DEFAULT '0' COMMENT '调度id',
  `type` tinyint DEFAULT NULL COMMENT '调度类型: 1 - 间隔调度 2 cron调度',
  `memo` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '调度配置',
  `priority` int DEFAULT NULL COMMENT '优先级',
  `next_trigger_time` bigint unsigned DEFAULT '0' COMMENT '下次触发时间',
  `prev_trigger_time` bigint unsigned DEFAULT '0' COMMENT '下次触发时间',
  `status` int unsigned DEFAULT '0' COMMENT '触发状态  1 - WAITING 2- EXECUTING 3 - MISFIRED 4 - COMPLETE',
  `start_time` bigint unsigned DEFAULT '0' COMMENT '开始触发时间',
  `end_time` bigint unsigned DEFAULT '0' COMMENT '开始触发时间',
  `data` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '{}' COMMENT '数据',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_taskId` (`task_id`,`schedule_id`) USING BTREE,
  KEY `idx_next_trigger_time` (`next_trigger_time`) USING BTREE,
  KEY `idx_status_next_trigger_time` (`status`,`next_trigger_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='任务定时配置';


-- tse_20.ts_task_queue definition

CREATE TABLE `ts_task_queue` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `tenant_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '租户id',
  `last_pull_time` datetime DEFAULT NULL COMMENT '最近拉取任务时间',
  `wait_task_cnt` int DEFAULT '0' COMMENT '任务数量',
  `total_task_cnt` int DEFAULT '0' COMMENT '任务总数量',
  `resource_group_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '资源组id',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk` (`tenant_id`,`resource_group_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='任务队列表';


-- tse_20.ts_task_queue_item definition

CREATE TABLE `ts_task_queue_item` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `tenant_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '租户id',
  `task_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '任务id',
  `priority` int DEFAULT '0' COMMENT '规则优先级',
  `process_instance_ids` varchar(700) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '进程ids',
  `status` tinyint unsigned DEFAULT '0' COMMENT '任务状态 0 - 未执行，1-执行中',
  `task_instance_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '任务实例id',
  `data` text CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT '任务内容',
  `resource_group_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '资源组id',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `idx_task` (`task_id`,`process_instance_ids`) USING BTREE,
  KEY `idx_tenant` (`tenant_id`,`resource_group_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='任务队列表';


-- tse_20.ts_task_relation definition

CREATE TABLE `ts_task_relation` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `pre_id` bigint unsigned DEFAULT '0',
  `post_id` bigint unsigned DEFAULT '0',
  `type` tinyint DEFAULT NULL COMMENT '类型 1-强依赖 ',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_pre_post` (`pre_id`,`post_id`) USING BTREE,
  KEY `idx_postId` (`post_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='任务依赖关系';


-- tse_20.ts_tenant definition

CREATE TABLE `ts_tenant` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '名称',
  `tenant_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '租户id',
  `global_config` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '全局配置',
  `strategy_config` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '任务策略配置信息',
  `create_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '创建人',
  `update_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '修改人',
  `delete_operator` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '删除人',
  `gmt_create` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `gmt_update` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  `gmt_delete` timestamp NULL DEFAULT NULL COMMENT '删除时间',
  `is_delete` bit(1) DEFAULT b'0' COMMENT '是否已删除',
  PRIMARY KEY (`id`),
  KEY `uk_tenantID` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

INSERT INTO ts_tenant (name,tenant_id,global_config,strategy_config,create_operator,update_operator,delete_operator,gmt_create,gmt_update,gmt_delete,is_delete) VALUES
         ('big_release','big_release','{"bigmetaUrl":"http://bigmetaaddr"}',NULL,'anonymous','anonymous',NULL,'2025-02-24 19:34:38.000','2025-02-24 19:34:38.000',NULL,0);
