RENAME TABLE `xxl_job_qrtz_trigger_info` TO `xxl_job_info`;

ALTER TABLE `xxl_job_info`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `xxl_job_info`
ADD COLUMN `schedule_type` varchar(50) NOT NULL DEFAULT 'CRON' COMMENT '调度类型';

ALTER TABLE `xxl_job_info`
MODIFY COLUMN `schedule_type` varchar(50) NOT NULL DEFAULT 'NONE' COMMENT '调度类型';

ALTER TABLE `xxl_job_info`
CHANGE COLUMN `job_cron` `schedule_conf` varchar(128) DEFAULT NULL COMMENT '调度配置，值含义取决于调度类型';

ALTER TABLE `xxl_job_info`
ADD COLUMN `misfire_strategy` varchar(50) NOT NULL DEFAULT 'DO_NOTHING' COMMENT '调度过期策略';

ALTER TABLE `xxl_job_info`
ADD COLUMN  `trigger_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '调度状态：0-停止，1-运行',
ADD COLUMN  `trigger_last_time` bigint(13) NOT NULL DEFAULT '0' COMMENT '上次调度时间',
ADD COLUMN  `trigger_next_time` bigint(13) NOT NULL DEFAULT '0' COMMENT '下次调度时间';

UPDATE `xxl_job_info`
SET trigger_status = CASE
    WHEN (SELECT TRIGGER_STATE FROM `xxl_job_qrtz_triggers` WHERE `xxl_job_info`.id = `xxl_job_qrtz_triggers`.JOB_NAME) = 'WAITING' THEN 0
    WHEN (SELECT TRIGGER_STATE FROM `xxl_job_qrtz_triggers` WHERE `xxl_job_info`.id = `xxl_job_qrtz_triggers`.JOB_NAME) = 'ACQUIRED' THEN 1
    ELSE 0 
 END;

ALTER TABLE `xxl_job_info`
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;




RENAME TABLE `xxl_job_qrtz_trigger_log` TO `xxl_job_log`;

ALTER TABLE `xxl_job_log`
MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

ALTER TABLE `xxl_job_log` ADD COLUMN  `alarm_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '告警状态：0-默认、1-无需告警、2-告警成功、3-告警失败';

ALTER TABLE `xxl_job_log` ADD INDEX `i_handle_code` (`handle_code`);

ALTER TABLE `xxl_job_log`
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


CREATE TABLE `xxl_job_log_report` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `trigger_day` datetime DEFAULT NULL COMMENT '调度-时间',
  `running_count` int(11) NOT NULL DEFAULT '0' COMMENT '运行中-日志数量',
  `suc_count` int(11) NOT NULL DEFAULT '0' COMMENT '执行成功-日志数量',
  `fail_count` int(11) NOT NULL DEFAULT '0' COMMENT '执行失败-日志数量',
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `i_trigger_day` (`trigger_day`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


RENAME TABLE `xxl_job_qrtz_trigger_logglue` TO `xxl_job_logglue`;

ALTER TABLE `xxl_job_logglue`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `xxl_job_logglue`
MODIFY `add_time` datetime DEFAULT NULL;

ALTER TABLE `xxl_job_logglue`
MODIFY `update_time` datetime DEFAULT NULL;

ALTER TABLE `xxl_job_logglue`
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;



RENAME TABLE `xxl_job_qrtz_trigger_registry` TO `xxl_job_registry`;

ALTER TABLE `xxl_job_registry`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `xxl_job_registry`
MODIFY `update_time` datetime DEFAULT NULL;

ALTER TABLE `xxl_job_registry` ADD INDEX `i_g_k_v` (`registry_group`,`registry_key`,`registry_value`);

ALTER TABLE `xxl_job_registry`
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;



RENAME TABLE `xxl_job_qrtz_trigger_group` TO `xxl_job_group`;

ALTER TABLE `xxl_job_group`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

ALTER TABLE `xxl_job_group` DROP COLUMN `order`;

ALTER TABLE `xxl_job_group` ADD COLUMN  `update_time` datetime DEFAULT NULL;

ALTER TABLE `xxl_job_group`
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;



CREATE TABLE `xxl_job_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL COMMENT '账号',
  `password` varchar(50) NOT NULL COMMENT '密码',
  `role` tinyint(4) NOT NULL COMMENT '角色：0-普通用户、1-管理员',
  `permission` varchar(255) DEFAULT NULL COMMENT '权限：执行器ID列表，多个逗号分割',
  PRIMARY KEY (`id`),
  UNIQUE KEY `i_username` (`username`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `xxl_job_user`(`id`, `username`, `password`, `role`, `permission`) VALUES (1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 1, NULL);

RENAME TABLE `xxl_job_qrtz_locks` TO `xxl_job_lock`;

ALTER TABLE `xxl_job_lock` DROP PRIMARY KEY;

ALTER TABLE `xxl_job_lock` DROP 
COLUMN `SCHED_NAME`;

ALTER TABLE `xxl_job_lock`
CHANGE COLUMN `LOCK_NAME` `lock_name` varchar(50) NOT NULL COMMENT '锁名称';

ALTER TABLE `xxl_job_lock`
ADD PRIMARY KEY (`lock_name`);

ALTER TABLE `xxl_job_lock`
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `xxl_job_lock` ( `lock_name`) VALUES ( 'schedule_lock');


DROP TABLE IF EXISTS `xxl_job_qrtz_blob_triggers`;

DROP TABLE IF EXISTS `xxl_job_qrtz_calendars`;

DROP TABLE IF EXISTS `xxl_job_qrtz_cron_triggers`;

DROP TABLE IF EXISTS `xxl_job_qrtz_fired_triggers`;

DROP TABLE IF EXISTS `xxl_job_qrtz_paused_trigger_grps`;

DROP TABLE IF EXISTS `xxl_job_qrtz_scheduler_state`;

DROP TABLE IF EXISTS `xxl_job_qrtz_simple_triggers`;

DROP TABLE IF EXISTS `xxl_job_qrtz_simprop_triggers`;

DROP TABLE IF EXISTS `xxl_job_qrtz_triggers`;

DROP TABLE IF EXISTS `xxl_job_qrtz_job_details`;
