25 lines
645 B
MySQL
25 lines
645 B
MySQL
|
alter table `vn`.`department`
|
||
|
add `twoFactor` ENUM ('email') null comment 'Default user two-factor auth type';
|
||
|
|
||
|
drop trigger `vn`.`department_afterUpdate`;
|
||
|
|
||
|
DELIMITER $$
|
||
|
$$
|
||
|
create definer = root@localhost trigger 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 ;
|