From 065f13557b9265d1e0903560c05be40d91b18039 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 7 Jan 2025 11:58:36 +0100 Subject: [PATCH] feat: refs #8357 Agregados triggers para manejar exclusiones de trabajadores en la tabla workerMana --- .../vn/triggers/workerManaExcluded_beforeInsert.sql | 9 +++++++++ .../vn/triggers/workerManaExcluded_beforeUpdate.sql | 9 +++++++++ db/routines/vn/triggers/workerMana_beforeInsert.sql | 10 ++++++++++ db/routines/vn/triggers/workerMana_beforeUpdate.sql | 10 ++++++++++ db/versions/11396-blueErica/00-firstScript.sql | 5 +++++ 5 files changed, 43 insertions(+) create mode 100644 db/routines/vn/triggers/workerManaExcluded_beforeInsert.sql create mode 100644 db/routines/vn/triggers/workerManaExcluded_beforeUpdate.sql create mode 100644 db/routines/vn/triggers/workerMana_beforeInsert.sql create mode 100644 db/routines/vn/triggers/workerMana_beforeUpdate.sql create mode 100644 db/versions/11396-blueErica/00-firstScript.sql diff --git a/db/routines/vn/triggers/workerManaExcluded_beforeInsert.sql b/db/routines/vn/triggers/workerManaExcluded_beforeInsert.sql new file mode 100644 index 000000000..824f0982b --- /dev/null +++ b/db/routines/vn/triggers/workerManaExcluded_beforeInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerManaExcluded_beforeInsert` + BEFORE INSERT ON `workerManaExcluded` + FOR EACH ROW +BEGIN + DELETE FROM workerMana + WHERE workerFk = NEW.workerFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workerManaExcluded_beforeUpdate.sql b/db/routines/vn/triggers/workerManaExcluded_beforeUpdate.sql new file mode 100644 index 000000000..83d73e131 --- /dev/null +++ b/db/routines/vn/triggers/workerManaExcluded_beforeUpdate.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerManaExcluded_beforeUpdate` + BEFORE UPDATE ON `workerManaExcluded` + FOR EACH ROW +BEGIN + DELETE FROM workerMana + WHERE workerFk = NEW.workerFk; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workerMana_beforeInsert.sql b/db/routines/vn/triggers/workerMana_beforeInsert.sql new file mode 100644 index 000000000..2d27004e3 --- /dev/null +++ b/db/routines/vn/triggers/workerMana_beforeInsert.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerMana_beforeInsert` + BEFORE INSERT ON `workerMana` + FOR EACH ROW +BEGIN + IF (SELECT EXISTS(SELECT TRUE FROM workerManaExcluded WHERE workerFk = NEW.workerFk)) THEN + CALL util.throw('Worker is excluded from mana'); + END IF; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/workerMana_beforeUpdate.sql b/db/routines/vn/triggers/workerMana_beforeUpdate.sql new file mode 100644 index 000000000..6916733cb --- /dev/null +++ b/db/routines/vn/triggers/workerMana_beforeUpdate.sql @@ -0,0 +1,10 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerMana_beforeUpdate` + BEFORE UPDATE ON `workerMana` + FOR EACH ROW +BEGIN + IF (SELECT EXISTS(SELECT TRUE FROM workerManaExcluded WHERE workerFk = NEW.workerFk)) THEN + CALL util.throw('Worker is excluded from mana'); + END IF; +END$$ +DELIMITER ; diff --git a/db/versions/11396-blueErica/00-firstScript.sql b/db/versions/11396-blueErica/00-firstScript.sql new file mode 100644 index 000000000..b21965fe8 --- /dev/null +++ b/db/versions/11396-blueErica/00-firstScript.sql @@ -0,0 +1,5 @@ +DELETE FROM vn.workerMana + WHERE workerFk IN ( + SELECT workerFk + FROM vn.workerManaExcluded + );