diff --git a/db/routines/vn/triggers/roadmapStop_beforeInsert.sql b/db/routines/vn/triggers/roadmapStop_beforeInsert.sql index b87a52bdc..9ec8b72cf 100644 --- a/db/routines/vn/triggers/roadmapStop_beforeInsert.sql +++ b/db/routines/vn/triggers/roadmapStop_beforeInsert.sql @@ -5,5 +5,10 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmapStop_beforeInser BEGIN SET NEW.editorFk = account.myUser_getId(); SET NEW.description = UCASE(NEW.description); + IF NEW.roadmapFk IS NOT NULL THEN + IF NEW.eta < (SELECT etd FROM roadmap WHERE id = NEW.roadmapFk) THEN + CALL util.throw('Departure time can not be after arrival time'); + END IF; + END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/roadmapStop_beforeUpdate.sql b/db/routines/vn/triggers/roadmapStop_beforeUpdate.sql index ec4dbe5ba..cff48846a 100644 --- a/db/routines/vn/triggers/roadmapStop_beforeUpdate.sql +++ b/db/routines/vn/triggers/roadmapStop_beforeUpdate.sql @@ -5,5 +5,12 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`roadmapStop_beforeUpdat BEGIN SET NEW.editorFk = account.myUser_getId(); SET NEW.description = UCASE(NEW.description); + IF (NOT (NEW.roadmapFk <=> OLD.roadmapFk) AND NEW.roadmapFk IS NOT NULL) + OR (NOT (NEW.eta <=> OLD.eta) AND NEW.eta IS NOT NULL) THEN + + IF NEW.eta < (SELECT etd FROM roadmap WHERE id = NEW.roadmapFk) THEN + CALL util.throw('Departure time can not be after arrival time'); + END IF; + END IF; END$$ DELIMITER ;