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;