CREATE TABLE IF NOT EXISTS `was_event_publisher_student` (
  `event_publisher_student_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` int(11) unsigned NOT NULL,
  `publisher_id` int(11) unsigned NOT NULL COMMENT "user_id of publisher",
  `student_id` int(11) unsigned NOT NULL COMMENT "user_id of student",
  `insert_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `update_timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`event_publisher_student_id`),
  KEY `idx_event_id` (`event_id`),
  KEY `idx_publisher_id` (`publisher_id`),
  KEY `idx_student_id` (`student_id`),
  KEY `idx_event_publisher_id` (`event_id`, `publisher_id`)
) ENGINE=InnoDB COMMENT="Store class share stats";

CREATE TRIGGER `was_event_publisher_student_insert_timestamp` BEFORE INSERT ON `was_event_publisher_student` FOR EACH ROW SET NEW.insert_timestamp = NOW();


INSERT INTO was_event_publisher_student (event_id, publisher_id, student_id)
SELECT DISTINCT e.event_id, e.user_id, wep.user_id
FROM was_event e
JOIN was_event_participant wep ON wep.event_id = e.event_id
JOIN wa_user u ON u.user_id = wep.user_id AND u.live = 1
WHERE e.user_id != wep.user_id
GROUP BY e.event_id, wep.user_id
