-- 1.0.349 将遗留 tenant_id=1 的 S8 完整运行链迁移到现有 AIDOPDemo。
-- 目标：tenant=797403760988230，factory=797403760988231。
SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS `ado_s8_alert_record_bak_1_0_349` LIKE `ado_s8_alert_record`;
INSERT IGNORE INTO `ado_s8_alert_record_bak_1_0_349` SELECT * FROM `ado_s8_alert_record` WHERE `tenant_id` = 1;
CREATE TABLE IF NOT EXISTS `ado_s8_alert_rule_bak_1_0_349` LIKE `ado_s8_alert_rule`;
INSERT IGNORE INTO `ado_s8_alert_rule_bak_1_0_349` SELECT * FROM `ado_s8_alert_rule` WHERE `tenant_id` = 1;
CREATE TABLE IF NOT EXISTS `ado_s8_data_source_bak_1_0_349` LIKE `ado_s8_data_source`;
INSERT IGNORE INTO `ado_s8_data_source_bak_1_0_349` SELECT * FROM `ado_s8_data_source` WHERE `tenant_id` = 1;
CREATE TABLE IF NOT EXISTS `ado_s8_detection_log_bak_1_0_349` LIKE `ado_s8_detection_log`;
INSERT IGNORE INTO `ado_s8_detection_log_bak_1_0_349` SELECT * FROM `ado_s8_detection_log` WHERE `tenant_id`=1 AND `id`<20000;
INSERT IGNORE INTO `ado_s8_detection_log_bak_1_0_349` SELECT * FROM `ado_s8_detection_log` WHERE `tenant_id`=1 AND `id`>=20000 AND `id`<40000;
INSERT IGNORE INTO `ado_s8_detection_log_bak_1_0_349` SELECT * FROM `ado_s8_detection_log` WHERE `tenant_id`=1 AND `id`>=40000 AND `id`<60000;
INSERT IGNORE INTO `ado_s8_detection_log_bak_1_0_349` SELECT * FROM `ado_s8_detection_log` WHERE `tenant_id`=1 AND `id`>=60000 AND `id`<80000;
INSERT IGNORE INTO `ado_s8_detection_log_bak_1_0_349` SELECT * FROM `ado_s8_detection_log` WHERE `tenant_id`=1 AND `id`>=80000 AND `id`<100000;
INSERT IGNORE INTO `ado_s8_detection_log_bak_1_0_349` SELECT * FROM `ado_s8_detection_log` WHERE `tenant_id`=1 AND `id`>=100000 AND `id`<120000;
INSERT IGNORE INTO `ado_s8_detection_log_bak_1_0_349` SELECT * FROM `ado_s8_detection_log` WHERE `tenant_id`=1 AND `id`>=120000 AND `id`<140000;
INSERT IGNORE INTO `ado_s8_detection_log_bak_1_0_349` SELECT * FROM `ado_s8_detection_log` WHERE `tenant_id`=1 AND `id`>=140000 AND `id`<160000;
INSERT IGNORE INTO `ado_s8_detection_log_bak_1_0_349` SELECT * FROM `ado_s8_detection_log` WHERE `tenant_id`=1 AND `id`>=160000;
CREATE TABLE IF NOT EXISTS `ado_s8_exception_bak_1_0_349` LIKE `ado_s8_exception`;
INSERT IGNORE INTO `ado_s8_exception_bak_1_0_349` SELECT * FROM `ado_s8_exception` WHERE `tenant_id` = 1;
CREATE TABLE IF NOT EXISTS `ado_s8_notification_layer_bak_1_0_349` LIKE `ado_s8_notification_layer`;
INSERT IGNORE INTO `ado_s8_notification_layer_bak_1_0_349` SELECT * FROM `ado_s8_notification_layer` WHERE `tenant_id` = 1;
CREATE TABLE IF NOT EXISTS `ado_s8_notification_log_bak_1_0_349` LIKE `ado_s8_notification_log`;
INSERT IGNORE INTO `ado_s8_notification_log_bak_1_0_349` SELECT * FROM `ado_s8_notification_log` WHERE `tenant_id` = 1;
CREATE TABLE IF NOT EXISTS `ado_s8_role_permission_config_bak_1_0_349` LIKE `ado_s8_role_permission_config`;
INSERT IGNORE INTO `ado_s8_role_permission_config_bak_1_0_349` SELECT * FROM `ado_s8_role_permission_config` WHERE `tenant_id` = 1;
CREATE TABLE IF NOT EXISTS `ado_s8_rule_detection_state_bak_1_0_349` LIKE `ado_s8_rule_detection_state`;
INSERT IGNORE INTO `ado_s8_rule_detection_state_bak_1_0_349` SELECT * FROM `ado_s8_rule_detection_state` WHERE `tenant_id` = 1;
CREATE TABLE IF NOT EXISTS `ado_s8_scene_config_bak_1_0_349` LIKE `ado_s8_scene_config`;
INSERT IGNORE INTO `ado_s8_scene_config_bak_1_0_349` SELECT * FROM `ado_s8_scene_config` WHERE `tenant_id` = 1;
CREATE TABLE IF NOT EXISTS `ado_s8_watch_rule_bak_1_0_349` LIKE `ado_s8_watch_rule`;
INSERT IGNORE INTO `ado_s8_watch_rule_bak_1_0_349` SELECT * FROM `ado_s8_watch_rule` WHERE `tenant_id` = 1;

UPDATE `ado_s8_alert_record` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1;
UPDATE `ado_s8_alert_rule` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1;
UPDATE `ado_s8_data_source` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1;
UPDATE `ado_s8_detection_log` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1 AND `id`<20000;
UPDATE `ado_s8_detection_log` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1 AND `id`>=20000 AND `id`<40000;
UPDATE `ado_s8_detection_log` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1 AND `id`>=40000 AND `id`<60000;
UPDATE `ado_s8_detection_log` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1 AND `id`>=60000 AND `id`<80000;
UPDATE `ado_s8_detection_log` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1 AND `id`>=80000 AND `id`<100000;
UPDATE `ado_s8_detection_log` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1 AND `id`>=100000 AND `id`<120000;
UPDATE `ado_s8_detection_log` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1 AND `id`>=120000 AND `id`<140000;
UPDATE `ado_s8_detection_log` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1 AND `id`>=140000 AND `id`<160000;
UPDATE `ado_s8_detection_log` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1 AND `id`>=160000;
UPDATE `ado_s8_exception` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1;
UPDATE `ado_s8_notification_layer` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1;
UPDATE `ado_s8_notification_log` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1;
UPDATE `ado_s8_role_permission_config` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1;
UPDATE `ado_s8_rule_detection_state` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1;
UPDATE `ado_s8_scene_config` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1;
UPDATE `ado_s8_watch_rule` SET `tenant_id`=797403760988230, `factory_id`=797403760988231 WHERE `tenant_id`=1;
