
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for job_jdbc_datasource
-- ----------------------------
DROP TABLE IF EXISTS `job_jdbc_datasource`;
CREATE TABLE `job_jdbc_datasource` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增主键',
  `datasource_name` varchar(200) NOT NULL COMMENT '数据源名称',
  `datasource` varchar(45) NOT NULL COMMENT '数据源',
  `datasource_group` varchar(200) DEFAULT 'Default' COMMENT '数据源分组',
  `database_name` varchar(45) NOT NULL COMMENT '数据库名',
  `jdbc_username` varchar(100) DEFAULT NULL COMMENT '用户名',
  `jdbc_password` varchar(200) DEFAULT NULL COMMENT '密码',
  `jdbc_url` varchar(500) NOT NULL COMMENT 'jdbc url',
  `jdbc_driver_class` varchar(200) DEFAULT NULL COMMENT 'jdbc驱动类',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态：0删除 1启用 2禁用',
  `create_by` varchar(20) DEFAULT NULL COMMENT '创建人',
  `create_time` int(20) DEFAULT NULL COMMENT '创建时间',
  `update_by` varchar(20) DEFAULT NULL COMMENT '更新人',
  `update_time` int(20) DEFAULT NULL COMMENT '更新时间',
  `comments` varchar(1000) DEFAULT NULL COMMENT '备注',
  `tag` varchar(20) DEFAULT NULL COMMENT '标签: 0开发1测试2开发',
  `kerberos` tinyint(1) NOT NULL COMMENT 'kerberos验证是否开启（0:不开启，1:开启）',
  `keytab` varchar(200) DEFAULT NULL COMMENT 'keytab文件',
  `krb5config` varchar(200) DEFAULT NULL COMMENT 'krb5config',
  `kerberos_service_name` varchar(100) DEFAULT NULL COMMENT 'kerberos_service_name',
  `principal` varchar(100) DEFAULT NULL COMMENT 'principal',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='jdbc数据源配置';


-- ----------------------------
-- Table structure for job_info
-- ----------------------------
DROP TABLE IF EXISTS `job_info`;
CREATE TABLE `job_info` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `cron_select_type` tinyint(4) NOT NULL COMMENT '周期选择类型',
  `job_cron` varchar(128) NOT NULL COMMENT '任务执行CRON',
  `job_desc` varchar(255) NOT NULL,
  `create_time` int(20) DEFAULT NULL COMMENT '创建时间',
  `update_time` int(20) DEFAULT NULL COMMENT '更新时间',
  `user_id` varchar(50) NOT NULL COMMENT '用户ID',
  `executor_route_strategy` varchar(50) DEFAULT NULL COMMENT '执行器路由策略',
  `executor_handler` varchar(255) DEFAULT NULL COMMENT '执行器任务handler',
  `executor_param` varchar(512) DEFAULT NULL COMMENT '执行器任务参数',
  `executor_block_strategy` varchar(50) DEFAULT NULL COMMENT '阻塞处理策略',
  `executor_timeout` int(11) NOT NULL DEFAULT '0' COMMENT '任务执行超时时间，单位秒',
  `executor_fail_retry_count` int(11) NOT NULL DEFAULT '0' COMMENT '失败重试次数',
  `trigger_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '调度状态：0-停止，1-运行',
  `trigger_last_time` bigint(13) DEFAULT NULL COMMENT '上次调度时间',
  `trigger_next_time` bigint(13) DEFAULT NULL COMMENT '下次调度时间',
  `job_json` text CHARACTER SET utf8 COMMENT 'datax运行脚本',
  `inc_start_time` int(11) DEFAULT NULL COMMENT '增量初始时间',
  `last_handle_code` int(11) DEFAULT NULL COMMENT '最近一次执行状态',
  `delete_status` tinyint(4) NOT NULL COMMENT '数据状态：0-无效，1-有效',
  `replace_param` varchar(50) DEFAULT NULL COMMENT '增量时间',
  `partition_info` varchar(50) DEFAULT NULL COMMENT '分区信息',
  `jvm_param` varchar(50) DEFAULT NULL COMMENT 'jvm参数',
  `last_time` varchar(50) DEFAULT NULL COMMENT '上次时间字段',
  `current_time` varchar(50) DEFAULT NULL COMMENT '当前时间字段',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;



-- ----------------------------
-- Table structure for job_log
-- ----------------------------
DROP TABLE IF EXISTS `job_log`;
CREATE TABLE `job_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `job_group` int(11) NOT NULL COMMENT '执行器主键ID',
  `job_id` int(11) NOT NULL COMMENT '任务，主键ID',
  `executor_address` varchar(255) DEFAULT NULL COMMENT '执行器地址，本次执行的地址',
  `executor_handler` varchar(255) DEFAULT NULL COMMENT '执行器任务handler',
  `executor_param` varchar(512) DEFAULT NULL COMMENT '执行器任务参数',
  `executor_sharding_param` varchar(20) DEFAULT NULL COMMENT '执行器任务分片参数，格式如 1/2',
  `executor_fail_retry_count` int(11) DEFAULT '0' COMMENT '失败重试次数',
  `trigger_time` bigint(13) DEFAULT NULL COMMENT '调度-时间',
  `trigger_code` int(11) NOT NULL COMMENT '调度-结果 0-失败，1-成功，2-无',
  `trigger_msg` text COMMENT '调度-日志',
  `handle_time` bigint(13) DEFAULT NULL COMMENT '执行-时间',
  `handle_code` int(11) NOT NULL COMMENT '执行-状态 0-失败，1-成功，2-无',
  `handle_msg` text COMMENT '执行-日志',
  `alarm_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '告警状态：0-默认、1-无需告警、2-告警成功、3-告警失败',
  `process_id` varchar(20) DEFAULT NULL COMMENT 'datax进程Id',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `I_trigger_time` (`trigger_time`) USING BTREE,
  KEY `I_handle_code` (`handle_code`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;

-- ----------------------------
-- Table structure for data_management
-- ----------------------------
DROP TABLE IF EXISTS `data_management`;
CREATE TABLE `data_management` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '数据名称',
  `data_type` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '数据类型',
  `data_num` int(20) DEFAULT NULL COMMENT '数据条数',
  `storage_location` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '存储位置',
  `storage_usage` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '占用存储',
  `storage_path` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '存储路径',
  `integrity` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '完整性',
  `create_time` bigint(13) NOT NULL COMMENT '创建时间',
  `user_name` varchar(20) COLLATE utf8_unicode_ci NOT NULL COMMENT '创建人名称',
  `user_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT '创建人编号',
  `project_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT '项目编号',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4  COMMENT='数据管理';

-- ----------------------------
-- Table structure for constant
-- ----------------------------
DROP TABLE IF EXISTS `constant`;
CREATE TABLE `constant` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `type` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT '常量类型',
  `value` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT '常量值',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4  COMMENT='常量表';

-- ----------------------------
-- Records of constant
-- ----------------------------
BEGIN;
INSERT INTO `constant` (`id`, `type`, `value`) VALUES (1, '作业类型', 'Java');
INSERT INTO `constant` (`id`, `type`, `value`) VALUES (2, '作业类型', 'Python');
INSERT INTO `constant` (`id`, `type`, `value`) VALUES (3, '作业类型', 'Dag');
INSERT INTO `constant` (`id`, `type`, `value`) VALUES (4, '作业标签', '业务预测');
INSERT INTO `constant` (`id`, `type`, `value`) VALUES (5, '作业标签', '作业监测');
INSERT INTO `constant` (`id`, `type`, `value`) VALUES (6, '作业标签', '人力系统');
INSERT INTO `constant` (`id`, `type`, `value`) VALUES (7, '任务标签', '业务预测');
INSERT INTO `constant` (`id`, `type`, `value`) VALUES (8, '任务标签', '任务监测');
INSERT INTO `constant` (`id`, `type`, `value`) VALUES (9, '任务标签', '人力系统');
COMMIT;

-- ----------------------------
-- Table structure for jm_homework
-- ----------------------------
DROP TABLE IF EXISTS `jm_homework`;
CREATE TABLE `jm_homework` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '作业名称',
  `type` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '作业类型',
  `tag` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '作业分类',
  `image_url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '执行镜像',
  `dag_uuid` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'DAG_ID',
  `dag_url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'DAG文件地址',
  `script_file` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '脚本文件',
  `execute_command` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '执行命令',
  `update_time` int(13) DEFAULT NULL COMMENT '更新时间',
  `create_time` int(13) NOT NULL COMMENT '创建时间',
  `user_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT '用户ID',
  `project_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT '项目ID',
  `status` tinyint(4) NOT NULL COMMENT '状态（0:已删除，1:未删除）',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4  COMMENT='作业信息';


-- ----------------------------
-- Table structure for jm_homework_datasource_relation
-- ----------------------------
DROP TABLE IF EXISTS `jm_homework_datasource_relation`;
CREATE TABLE `jm_homework_datasource_relation` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `type` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '类型',
  `datasource_id` bigint(20) NOT NULL COMMENT '数据源ID',
  `node_uuid` varchar(32) COLLATE utf8_unicode_ci NOT NULL COMMENT '节点uuid',
  `table` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '数据源对应数据表',
  `homework_id` bigint(20) NOT NULL COMMENT '作业ID',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4  COMMENT='作业与数据源关系表';

-- ----------------------------
-- Table structure for jm_job_info
-- ----------------------------
DROP TABLE IF EXISTS `jm_job_info`;
CREATE TABLE `jm_job_info` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT '任务名称',
  `type` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT '任务类型',
  `tag` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT '任务分类',
  `cron_type` tinyint(4) NOT NULL COMMENT '周期类型(1:单次;2:循环)',
  `cron_select_type` tinyint(4) DEFAULT NULL COMMENT '选择周期类型(0:时,1:日,2:周,3:月,4:cron)',
  `cron_expression` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '周期表达式',
  `api` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'api调用',
  `json_str` varchar(10000) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '图形信息',
  `status` tinyint(4) NOT NULL COMMENT '状态(0:停用中;1:启用中)',
  `delete_status` tinyint(4) NOT NULL COMMENT '是否删除(0:已删除;1:未删除)',
  `user_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT '用户ID',
  `user_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT '用户名称',
  `project_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT '项目ID',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4  COMMENT='定时任务详情';


-- ----------------------------
-- Table structure for jm_job_node
-- ----------------------------
DROP TABLE IF EXISTS `jm_job_node`;
CREATE TABLE `jm_job_node` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `job_id` bigint(20) NOT NULL COMMENT '任务ID',
  `homework_id` bigint(20) DEFAULT NULL COMMENT '作业ID',
  `homework_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT '作业名称',
  `start_point` tinyint(4) NOT NULL COMMENT '起始点（0:起始点；1:非起始点）',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4  COMMENT='Job节点表';


-- ----------------------------
-- Table structure for jm_job_edge
-- ----------------------------
DROP TABLE IF EXISTS `jm_job_edge`;
CREATE TABLE `jm_job_edge` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `in_node_id` bigint(20) DEFAULT NULL,
  `out_node_id` bigint(20) DEFAULT NULL,
  `job_id` bigint(20) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4  COMMENT='Job节点关系表';


-- ----------------------------
-- Table structure for relation
-- ----------------------------
DROP TABLE IF EXISTS `relation`;
CREATE TABLE `relation` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `se_id` bigint(20) DEFAULT NULL COMMENT '服务端id（debug时不存在）',
  `type` varchar(20) COLLATE utf8_unicode_ci NOT NULL COMMENT '（datax,job,task,debug）',
  `af_id` int(11) NOT NULL COMMENT 'airflow端id',
  `dag_uuid` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'dag_uuid(仅在debug时存在)',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ;

-- ----------------------------
-- Table structure for airflow_job
-- ----------------------------
DROP TABLE IF EXISTS `airflow_job`;
CREATE TABLE `airflow_job` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` text COLLATE utf8_unicode_ci,
  `job_type` int(11) DEFAULT NULL,
  `tasks` json DEFAULT NULL,
  `dependence` json DEFAULT NULL,
  `cron` text COLLATE utf8_unicode_ci NOT NULL,
  `desc` text COLLATE utf8_unicode_ci NOT NULL,
  `route_strategy` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
  `block_strategy` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
  `executor_timeout` int(11) NOT NULL,
  `executor_fail_retry_count` int(11) NOT NULL,
  `trigger_status` int(11) NOT NULL,
  `trigger_last_time` int(11) DEFAULT NULL,
  `trigger_next_time` int(11) DEFAULT NULL,
  `create_time` int(11) DEFAULT NULL,
  `update_time` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `job_mode` int(2) DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `ix_airflow_job_id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Table structure for airflow_run
-- ----------------------------
DROP TABLE IF EXISTS `airflow_run`;
CREATE TABLE `airflow_run` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `start_time` double DEFAULT NULL,
  `end_time` float DEFAULT NULL,
  `job_id` int(11) DEFAULT NULL,
  `af_run_id` varchar(60) COLLATE utf8_unicode_ci DEFAULT NULL,
  `status` int(11) DEFAULT NULL,
  `details` json DEFAULT NULL,
  `run_ts` varchar(60) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `ix_airflow_run_id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Table structure for airflow_task
-- ----------------------------
DROP TABLE IF EXISTS `airflow_task`;
CREATE TABLE `airflow_task` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` text COLLATE utf8_unicode_ci,
  `task_type` varchar(16) COLLATE utf8_unicode_ci DEFAULT NULL,
  `file_urls` json DEFAULT NULL,
  `script` text COLLATE utf8_unicode_ci,
  `cmd` text COLLATE utf8_unicode_ci,
  `cmd_parameters` text COLLATE utf8_unicode_ci,
  `envs` json DEFAULT NULL,
  `run_image` text COLLATE utf8_unicode_ci,
  `create_time` int(11) DEFAULT NULL,
  `update_time` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `ix_airflow_task_id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- ----------------------------
-- Alter for data_management
-- ----------------------------
ALTER TABLE `data_management`
DROP COLUMN `data_type`,
DROP COLUMN `data_num`,
DROP COLUMN `storage_location`,
DROP COLUMN `storage_usage`,
DROP COLUMN `storage_path`,
DROP COLUMN `integrity`,
ADD COLUMN `table_name` varchar(255) NULL COMMENT '表名' AFTER `name`;

-- ----------------------------
-- Alter for constant
-- ----------------------------
ALTER TABLE `constant`
MODIFY COLUMN `value` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '常量值' AFTER `type`;

SET FOREIGN_KEY_CHECKS = 1;