Skip to content

Commit

Permalink
feature: 异常通知的收敛/抑制能力 TencentBlueKing#205
Browse files Browse the repository at this point in the history
SQL改造成幂等语句
  • Loading branch information
wadema committed Sep 13, 2021
1 parent 9929d4d commit 1979d25
Showing 1 changed file with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
use job_crontab;

SET NAMES utf8mb4;
USE job_crontab;

ALTER TABLE `job_crontab`.`cron_job` ADD COLUMN `last_execute_error_code` bigint(20) UNSIGNED NULL DEFAULT NULL AFTER `last_execute_status`;
use job_crontab;

SET NAMES utf8mb4;

DROP PROCEDURE IF EXISTS job_schema_update;

DELIMITER <JOB_UBF>

CREATE PROCEDURE job_schema_update()
BEGIN

DECLARE db VARCHAR(100);
SET AUTOCOMMIT = 0;
SELECT DATABASE() INTO db;

IF NOT EXISTS(SELECT 1
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = db
AND TABLE_NAME = 'cron_job'
AND COLUMN_NAME = 'last_execute_error_code') THEN
ALTER TABLE cron_job ADD COLUMN `last_execute_error_code` bigint(20) UNSIGNED NULL DEFAULT NULL AFTER `last_execute_status`;
END IF;

IF NOT EXISTS(SELECT 1
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = db
AND TABLE_NAME = 'cron_job'
AND COLUMN_NAME = 'last_execute_error_count') THEN
ALTER TABLE cron_job ADD COLUMN `last_execute_error_count` int(11) UNSIGNED NOT NULL DEFAULT '0' AFTER `last_execute_error_code`;
END IF;

COMMIT;
END <JOB_UBF>
DELIMITER ;
COMMIT;
CALL job_schema_update();

ALTER TABLE `job_crontab`.`cron_job` ADD COLUMN `last_execute_error_count` int(11) UNSIGNED NOT NULL DEFAULT '0' AFTER `last_execute_error_code`;
DROP PROCEDURE IF EXISTS job_schema_update;

0 comments on commit 1979d25

Please sign in to comment.