From 477646ba311893f8a22e47785fdd5dbd7fff597e Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 20 Jan 2025 14:43:14 +0100 Subject: [PATCH 1/2] feat: refs #8227 Roadmap changes --- .../procedures/vehicle_checkNumberPlate.sql | 27 ++++++++++++++----- .../vn/triggers/roadmap_beforeInsert.sql | 2 ++ .../vn/triggers/roadmap_beforeUpdate.sql | 2 ++ .../11416-goldenTulip/00-firstScript.sql | 5 ++++ 4 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 db/versions/11416-goldenTulip/00-firstScript.sql diff --git a/db/routines/vn/procedures/vehicle_checkNumberPlate.sql b/db/routines/vn/procedures/vehicle_checkNumberPlate.sql index cbbcbec63..613dda368 100644 --- a/db/routines/vn/procedures/vehicle_checkNumberPlate.sql +++ b/db/routines/vn/procedures/vehicle_checkNumberPlate.sql @@ -1,17 +1,30 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`vehicle_checkNumberPlate`(vNumberPlate VARCHAR(10), vCountryCodeFk VARCHAR(2)) +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`vehicle_checkNumberPlate`( + vNumberPlate VARCHAR(10), + vCountryCodeFk VARCHAR(2) +) BEGIN /** - * Comprueba si la matricula pasada tiene el formato correcto dependiendo del pais del vehiculo + * Comprueba si la matricula pasada tiene el formato + * correcto dependiendo del pais del vehiculo. + * + * @param vNumberPlate Número de matricula + * @param vCountryCodeFk Código de pais */ DECLARE vRegex VARCHAR(45); - SELECT vp.regex INTO vRegex - FROM vehiclePlateRegex vp - WHERE vp.countryCodeFk = vCountryCodeFk; - + IF vCountryCodeFk IS NULL THEN + SET vRegex = '^[A-Z0-9 -]{6,12}$'; + ELSE + SELECT regex INTO vRegex + FROM vehiclePlateRegex + WHERE countryCodeFk = vCountryCodeFk; + END IF; + IF NOT vNumberPlate REGEXP BINARY (vRegex)THEN - CALL util.throw(CONCAT('Error: la matricula ', vNumberPlate, ' no es valida para ',vCountryCodeFk)); + CALL util.throw(CONCAT('La matricula ', vNumberPlate, + ' no es valida', IF(vCountryCodeFk IS NOT NULL, + CONCAT(' para ', vCountryCodeFk), ''))); END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/roadmap_beforeInsert.sql b/db/routines/vn/triggers/roadmap_beforeInsert.sql index 2f9481140..0a4386e63 100644 --- a/db/routines/vn/triggers/roadmap_beforeInsert.sql +++ b/db/routines/vn/triggers/roadmap_beforeInsert.sql @@ -3,6 +3,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmap_beforeInsert` BEFORE INSERT ON `roadmap` FOR EACH ROW BEGIN + CALL vehicle_checkNumberPlate(NEW.tractorPlate, NULL); + CALL vehicle_checkNumberPlate(NEW.trailerPlate, NULL); IF NEW.driver1Fk IS NOT NULL THEN SET NEW.driverName = (SELECT firstName FROM worker WHERE id = NEW.driver1Fk); ELSE diff --git a/db/routines/vn/triggers/roadmap_beforeUpdate.sql b/db/routines/vn/triggers/roadmap_beforeUpdate.sql index a2a02e96a..b381854ed 100644 --- a/db/routines/vn/triggers/roadmap_beforeUpdate.sql +++ b/db/routines/vn/triggers/roadmap_beforeUpdate.sql @@ -3,6 +3,8 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmap_beforeUpdate` BEFORE UPDATE ON `roadmap` FOR EACH ROW BEGIN + CALL vehicle_checkNumberPlate(NEW.tractorPlate, NULL); + CALL vehicle_checkNumberPlate(NEW.trailerPlate, NULL); IF NEW.driver1Fk IS NOT NULL THEN SET NEW.driverName = (SELECT firstName FROM worker WHERE id = NEW.driver1Fk); ELSE diff --git a/db/versions/11416-goldenTulip/00-firstScript.sql b/db/versions/11416-goldenTulip/00-firstScript.sql new file mode 100644 index 000000000..9b89fcfa6 --- /dev/null +++ b/db/versions/11416-goldenTulip/00-firstScript.sql @@ -0,0 +1,5 @@ +ALTER TABLE vn.roadmap + MODIFY COLUMN m3 int(10) unsigned DEFAULT NULL NULL COMMENT 'Capacidad máxima del remolque'; +ALTER TABLE vn.route + ADD roadmapStopFk int(11) NULL, + ADD CONSTRAINT route_roadmapStop_FK FOREIGN KEY (roadmapStopFk) REFERENCES vn.roadmapStop(id) ON DELETE RESTRICT ON UPDATE CASCADE; -- 2.40.1 From 482fe77159f72144b3f733f7b86df44509586987 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 21 Jan 2025 14:03:50 +0100 Subject: [PATCH 2/2] feat: refs #8227 Roadmap changes --- db/dump/fixtures.before.sql | 4 ++-- db/routines/vn/triggers/roadmapStop_beforeInsert.sql | 3 +-- db/routines/vn/triggers/roadmapStop_beforeUpdate.sql | 3 +-- db/routines/vn/triggers/roadmap_beforeInsert.sql | 12 ++++++------ db/routines/vn/triggers/roadmap_beforeUpdate.sql | 12 ++++++------ db/versions/11416-goldenTulip/00-firstScript.sql | 8 ++++---- db/versions/11416-goldenTulip/01-firstScript.sql | 1 + db/versions/11416-goldenTulip/02-firstScript.sql | 4 ++++ 8 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 db/versions/11416-goldenTulip/01-firstScript.sql create mode 100644 db/versions/11416-goldenTulip/02-firstScript.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 590fe34b6..cc1a9fc6f 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -2749,13 +2749,13 @@ INSERT INTO `vn`.`roadmapAddress` (`addressFk`) (3), (4); -INSERT INTO `vn`.`roadmap` (`id`, `name`, `tractorPlate`, `trailerPlate`, `phone`, `supplierFk`, `etd`, `observations`, `userFk`, `price`, `driverName`) +INSERT INTO `vn`.`roadmap` (`id`, `name`, `tractorPlate`, `trailerPlate`, `phone`, `supplierFk`, `etd`, `observations`, `editorFk`, `price`, `driverName`) VALUES (1, 'val-algemesi', '1234-BCD', '9876-BCD', '111111111', 1, util.VN_NOW(), 'this is test observation', 1, 15, 'Batman'), (2, 'alg-valencia', '2345-CDF', '8765-BCD', '111111111', 1, util.VN_NOW(), 'test observation', 1, 20, 'Robin'), (3, 'alz-algemesi', '3456-DFG', '7654-BCD', '222222222', 2, DATE_ADD(util.VN_NOW(), INTERVAL 2 DAY), 'observations...', 2, 25, 'Driverman'); -INSERT INTO `vn`.`roadmapStop` (`id`, `roadmapFk`, `addressFk`, `eta`, `description`, `userFk`) +INSERT INTO `vn`.`roadmapStop` (`id`, `roadmapFk`, `addressFk`, `eta`, `description`, `editorFk`) VALUES (1, 1, 1, DATE_ADD(util.VN_NOW(), INTERVAL 1 DAY), 'Best truck in fleet', 1), (2, 1, 2, DATE_ADD(util.VN_NOW(), INTERVAL '1 2' DAY_HOUR), 'Second truck in fleet', 1), diff --git a/db/routines/vn/triggers/roadmapStop_beforeInsert.sql b/db/routines/vn/triggers/roadmapStop_beforeInsert.sql index d71942fea..b87a52bdc 100644 --- a/db/routines/vn/triggers/roadmapStop_beforeInsert.sql +++ b/db/routines/vn/triggers/roadmapStop_beforeInsert.sql @@ -3,8 +3,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmapStop_beforeInser BEFORE INSERT ON `roadmapStop` FOR EACH ROW BEGIN - + SET NEW.editorFk = account.myUser_getId(); SET NEW.description = UCASE(NEW.description); - END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/roadmapStop_beforeUpdate.sql b/db/routines/vn/triggers/roadmapStop_beforeUpdate.sql index c3cbf2597..ec4dbe5ba 100644 --- a/db/routines/vn/triggers/roadmapStop_beforeUpdate.sql +++ b/db/routines/vn/triggers/roadmapStop_beforeUpdate.sql @@ -3,8 +3,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmapStop_beforeUpdat BEFORE UPDATE ON `roadmapStop` FOR EACH ROW BEGIN - + SET NEW.editorFk = account.myUser_getId(); SET NEW.description = UCASE(NEW.description); - END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/roadmap_beforeInsert.sql b/db/routines/vn/triggers/roadmap_beforeInsert.sql index 0a4386e63..118653d44 100644 --- a/db/routines/vn/triggers/roadmap_beforeInsert.sql +++ b/db/routines/vn/triggers/roadmap_beforeInsert.sql @@ -3,12 +3,12 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmap_beforeInsert` BEFORE INSERT ON `roadmap` FOR EACH ROW BEGIN - CALL vehicle_checkNumberPlate(NEW.tractorPlate, NULL); - CALL vehicle_checkNumberPlate(NEW.trailerPlate, NULL); - IF NEW.driver1Fk IS NOT NULL THEN - SET NEW.driverName = (SELECT firstName FROM worker WHERE id = NEW.driver1Fk); - ELSE - SET NEW.driverName = NULL; + SET NEW.editorFk = account.myUser_getId(); + IF NEW.tractorPlate IS NOT NULL THEN + CALL vehicle_checkNumberPlate(NEW.tractorPlate, NULL); + END IF; + IF NEW.trailerPlate IS NOT NULL THEN + CALL vehicle_checkNumberPlate(NEW.trailerPlate, 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 index b381854ed..a60b1e892 100644 --- a/db/routines/vn/triggers/roadmap_beforeUpdate.sql +++ b/db/routines/vn/triggers/roadmap_beforeUpdate.sql @@ -3,12 +3,12 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmap_beforeUpdate` BEFORE UPDATE ON `roadmap` FOR EACH ROW BEGIN - CALL vehicle_checkNumberPlate(NEW.tractorPlate, NULL); - CALL vehicle_checkNumberPlate(NEW.trailerPlate, NULL); - IF NEW.driver1Fk IS NOT NULL THEN - SET NEW.driverName = (SELECT firstName FROM worker WHERE id = NEW.driver1Fk); - ELSE - SET NEW.driverName = NULL; + SET NEW.editorFk = account.myUser_getId(); + IF NEW.tractorPlate IS NOT NULL THEN + CALL vehicle_checkNumberPlate(NEW.tractorPlate, NULL); + END IF; + IF NEW.trailerPlate IS NOT NULL THEN + CALL vehicle_checkNumberPlate(NEW.trailerPlate, NULL); END IF; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/versions/11416-goldenTulip/00-firstScript.sql b/db/versions/11416-goldenTulip/00-firstScript.sql index 9b89fcfa6..d06f25493 100644 --- a/db/versions/11416-goldenTulip/00-firstScript.sql +++ b/db/versions/11416-goldenTulip/00-firstScript.sql @@ -1,5 +1,5 @@ ALTER TABLE vn.roadmap - MODIFY COLUMN m3 int(10) unsigned DEFAULT NULL NULL COMMENT 'Capacidad máxima del remolque'; -ALTER TABLE vn.route - ADD roadmapStopFk int(11) NULL, - ADD CONSTRAINT route_roadmapStop_FK FOREIGN KEY (roadmapStopFk) REFERENCES vn.roadmapStop(id) ON DELETE RESTRICT ON UPDATE CASCADE; + MODIFY COLUMN m3 int(10) unsigned DEFAULT NULL NULL COMMENT 'Capacidad máxima del remolque', + CHANGE driver1Fk driverFk int(10) unsigned DEFAULT NULL NULL COMMENT 'Conductor principal' AFTER driverName, + CHANGE driver2Fk codriverFk int(10) unsigned DEFAULT NULL NULL COMMENT 'Copiloto' AFTER driverFk, + CHANGE userFk editorFk int(10) unsigned DEFAULT NULL NULL AFTER m3; \ No newline at end of file diff --git a/db/versions/11416-goldenTulip/01-firstScript.sql b/db/versions/11416-goldenTulip/01-firstScript.sql new file mode 100644 index 000000000..76b69387c --- /dev/null +++ b/db/versions/11416-goldenTulip/01-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.roadmapStop CHANGE userFk editorFk int(10) unsigned DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/versions/11416-goldenTulip/02-firstScript.sql b/db/versions/11416-goldenTulip/02-firstScript.sql new file mode 100644 index 000000000..89833fe8b --- /dev/null +++ b/db/versions/11416-goldenTulip/02-firstScript.sql @@ -0,0 +1,4 @@ +ALTER TABLE vn.route + ADD roadmapStopFk int(11) NULL, + ADD CONSTRAINT route_roadmapStop_FK FOREIGN KEY (roadmapStopFk) REFERENCES vn.roadmapStop(id) ON DELETE RESTRICT ON UPDATE CASCADE, + CHANGE editorFk editorFk int(10) unsigned DEFAULT NULL NULL AFTER roadmapStopFk; -- 2.40.1