DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `hedera`.`orderRow_beforeInsert`
	BEFORE INSERT ON `orderRow`
	FOR EACH ROW
BEGIN
	DECLARE vIsFirst BOOL;

	SELECT (first_row_stamp IS NULL) INTO vIsFirst  
		FROM `order` 
		WHERE id = NEW.orderFk;

	IF vIsFirst THEN
		UPDATE `order` SET first_row_stamp = util.VN_NOW() 
			WHERE id = NEW.orderFk;
	END IF;
END$$
DELIMITER ;
