diff --git a/db/changes/233601/00-updateAfterBusinnesInsert.sql b/db/changes/233601/00-updateAfterBusinnesInsert.sql new file mode 100644 index 000000000..f2b5dc753 --- /dev/null +++ b/db/changes/233601/00-updateAfterBusinnesInsert.sql @@ -0,0 +1,42 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`business_afterInsert` + AFTER INSERT ON `business` + FOR EACH ROW +BEGIN + CALL worker_updateBusiness(NEW.workerFk); + + IF ( + SELECT NOT active + FROM account.user + WHERE id = NEW.workerFk + ) THEN + UPDATE account.user + SET active = TRUE + WHERE id = NEW.workerFk; + END IF; + + IF ( + SELECT NOT COUNT(aa.id) + FROM account.mailAliasAccount aa + JOIN account.mailAlias ma ON ma.id = aa.mailAlias + WHERE aa.account = NEW.workerFk + AND ma.alias = 'general' + ) THEN + INSERT INTO account.mailAliasAccount (mailAlias, account) + SELECT id, NEW.workerFk + FROM account.mailAlias + WHERE alias = 'general'; + END IF; + + IF ( + SELECT NOT COUNT(account) + FROM account.mailForward + WHERE account = NEW.workerFk + ) THEN + INSERT INTO account.mailForward (account, forwardTo) + SELECT NEW.workerFk, email + FROM account.user + WHERE id = NEW.workerFk; + END IF; +END$$ +DELIMITER ; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index b01c07461..a3d76015f 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1965,6 +1965,11 @@ INSERT INTO `vn`.`calendarType` (`id`, `description`, `hoursWeek`, `isPartial`) VALUES (1, 'General schedule', 40, 0); +INSERT INTO `account`.`account`(id) + SELECT u.id + FROM account.user u + LEFT JOIN account.account a ON a.id = u.id + WHERE a.id IS NULL; DROP TEMPORARY TABLE IF EXISTS tmp.worker; CREATE TEMPORARY TABLE tmp.worker