DROP TRIGGER IF EXISTS `add_newsfeed_trig`;
DELIMITER ;;
CREATE TRIGGER `add_newsfeed_trig`
AFTER INSERT ON `newsfeed`
FOR EACH ROW 
BEGIN
  DECLARE user_type_var INT;
  SELECT type.user_type INTO user_type_var FROM user_type_t AS type INNER JOIN users AS user ON user.type = type.user_type WHERE user.id = NEW.user_id;
  INSERT INTO `audit_trail` (`action_type`,`user_id`,`user_type`,`action_timestamp`) VALUES (10,NEW.user_id,user_type_var,NOW());
END;;
DELIMITER ;
