/*
 Navicat Premium Data Transfer

 Source Server         : data
 Source Server Type    : SQLite
 Source Server Version : 3021000
 Source Schema         : main

 Target Server Type    : SQLite
 Target Server Version : 3021000
 File Encoding         : 65001

 Date: 24/07/2024 15:42:52
*/

PRAGMA foreign_keys = false;

DROP TRIGGER IF EXISTS "del_device_id";
-- ----------------------------
-- Triggers structure for table device
-- ----------------------------
CREATE TRIGGER "update_device_id"
AFTER UPDATE OF "id"
ON "device"
BEGIN
    UPDATE task_instruction SET device_id = NEW.id
    WHERE task_instruction.device_id = OLD.id;
END;


CREATE TRIGGER "update_dev_model_id"
AFTER UPDATE OF "id"
ON "dev_model"
BEGIN
    UPDATE instruction SET dev_model_id = NEW.id
    WHERE instruction.dev_model_id = OLD.id;
		UPDATE device SET dev_model_id = NEW.id
    WHERE device.dev_model_id = OLD.id;
END;
-- ----------------------------
-- Triggers structure for table instruction
-- ----------------------------

CREATE TRIGGER "update_instruction_id"
AFTER UPDATE OF "id"
ON "instruction"
BEGIN
    UPDATE task_instruction SET target_id = NEW.id
    WHERE task_instruction.target_id = OLD.id AND task_instruction.target_type = 'instruction';
END;

-- ----------------------------
-- Triggers structure for table task
-- ----------------------------
CREATE TRIGGER "update_task_id"
AFTER UPDATE OF "id"
ON "task"
BEGIN
    UPDATE task_instruction SET target_id = NEW.id
    WHERE task_instruction.target_id = OLD.id AND task_instruction.target_type = 'task';
		UPDATE task_instruction SET task_id = NEW.id
    WHERE task_instruction.task_id = OLD.id;
END;
-- ----------------------------
-- Triggers structure for table task_group
-- ----------------------------
CREATE TRIGGER "update_task_group_id"
AFTER UPDATE OF "id"
ON "task_group"
BEGIN
    UPDATE task SET group_id = NEW.id
    WHERE task.group_id = OLD.id;
END;
PRAGMA foreign_keys = true;
