diff --git a/db/routines/vn/triggers/roadmap_beforeInsert.sql b/db/routines/vn/triggers/roadmap_beforeInsert.sql new file mode 100644 index 000000000..df07d5540 --- /dev/null +++ b/db/routines/vn/triggers/roadmap_beforeInsert.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`roadmap_beforeInsert` + BEFORE INSERT ON `roadmap` + FOR EACH ROW +BEGIN + IF NEW.driver1Fk IS NOT NULL THEN + SET NEW.driverName = (SELECT firstName FROM worker WHERE id = NEW.driver1Fk); + ELSE + SET NEW.driverName = NULL; + END IF; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/roadmap_beforeUpdate.sql b/db/routines/vn/triggers/roadmap_beforeUpdate.sql new file mode 100644 index 000000000..4905a0442 --- /dev/null +++ b/db/routines/vn/triggers/roadmap_beforeUpdate.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`roadmap_beforeUpdate` + BEFORE UPDATE ON `roadmap` + FOR EACH ROW +BEGIN + IF NEW.driver1Fk IS NOT NULL THEN + SET NEW.driverName = (SELECT firstName FROM worker WHERE id = NEW.driver1Fk); + ELSE + SET NEW.driverName = NULL; + END IF; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/11195-salmonPalmetto/00-firstScript.sql b/db/versions/11195-salmonPalmetto/00-firstScript.sql new file mode 100644 index 000000000..980b66c8d --- /dev/null +++ b/db/versions/11195-salmonPalmetto/00-firstScript.sql @@ -0,0 +1,6 @@ +ALTER TABLE vn.roadmap + ADD COLUMN m3 INT UNSIGNED NULL, + ADD COLUMN driver2Fk INT UNSIGNED NULL, + ADD COLUMN driver1Fk INT UNSIGNED NULL, + ADD CONSTRAINT roadmap_worker_FK FOREIGN KEY (driver1Fk) REFERENCES vn.worker(id) ON DELETE RESTRICT ON UPDATE CASCADE, + ADD CONSTRAINT roadmap_worker_FK_2 FOREIGN KEY (driver2Fk) REFERENCES vn.worker(id) ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file