text: DROP TRIGGER IF EXISTS trg2_group_member_insert_open_group_only;
  
  delimiter //
  
  CREATE TRIGGER `trg2_group_member_insert_open_group_only` BEFORE INSERT ON group_member
  
  FOR EACH ROW
  BEGIN
  	DECLARE isClosed BOOLEAN;
  	SELECT is_closed FROM usergroup WHERE group_id = NEW.group_id INTO isClosed;
      IF isClosed = 1 THEN
  		SIGNAL SQLSTATE '45000'
  		SET MESSAGE_TEXT='Group is closed', MYSQL_ERRNO=3001;
      END IF;
  END; //
  
  delimiter ;
  