18 lines
468 B
MySQL
18 lines
468 B
MySQL
|
DELIMITER $$
|
||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`department_afterUpdate`
|
||
|
AFTER UPDATE ON `department`
|
||
|
FOR EACH ROW
|
||
|
BEGIN
|
||
|
IF !(OLD.parentFk <=> NEW.parentFk) THEN
|
||
|
UPDATE vn.department_recalc SET isChanged = TRUE;
|
||
|
END IF;
|
||
|
|
||
|
IF !(OLD.twoFactor <=> NEW.twoFactor) THEN
|
||
|
UPDATE account.user u
|
||
|
JOIN vn.workerDepartment wd ON wd.workerFk = u.id
|
||
|
SET u.twoFactor = NEW.twoFactor
|
||
|
WHERE wd.departmentFk = NEW.id;
|
||
|
END IF;
|
||
|
END$$
|
||
|
DELIMITER ;
|