SET FOREIGN_KEY_CHECKS=0;

ALTER TABLE `zkt_alarm_record` DROP INDEX `INDEX_ALARM_ITEM_OBJ_TAR`;

ALTER TABLE `zkt_alarm_record` ADD COLUMN `ITEM_ID` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '报警类型ID' AFTER `END_TIME`;

ALTER TABLE `zkt_alarm_record` MODIFY COLUMN `DEFINITION_ID` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '报警定义ID（报警对象ID-报警类型ID）' FIRST;

ALTER TABLE `zkt_alarm_record` MODIFY COLUMN `PROJECT_ID` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '项目ID' AFTER `DEFINITION_ID`;

ALTER TABLE `zkt_alarm_record` MODIFY COLUMN `ITEM_CODE` varchar(42) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '报警条目编码' AFTER `OBJ_ID`;

ALTER TABLE `zkt_alarm_record` DROP COLUMN `TARGET_ID`;

ALTER TABLE `zkt_alarm_record` ADD UNIQUE INDEX `INDEX_ALARM_ITEM_OBJ_TAR`(`ITEM_CODE`, `OBJ_ID`) USING BTREE COMMENT '一个报警条目，一个对象在一个报警报警匹配规则只能对应一条报警定义';

SET FOREIGN_KEY_CHECKS=1;
