

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;

ALTER TABLE `wa_wabinar_broadcaster` ADD `student_count` int(11) NOT NULL DEFAULT '0' AFTER `embed_chat`;

UPDATE wa_wabinar_broadcaster wb SET wb.student_count = 
( 
    SELECT COUNT(DISTINCT(eps.student_id)) 
    FROM was_event_publisher_student eps
    WHERE eps.publisher_id = wb.user_id
);


UPDATE
	was_user_group
SET
	membership_level = 'PREMIUM'
WHERE
	`name` in('Lite', 'Premium', 'Premium Limited', '500 Dedicated Hosting Server');


UPDATE
	was_user_group
SET
	membership_level = 'PPLUS'
WHERE
	`name` in('Admin');


UPDATE
	wap_r_resource
SET
	video_start_image = REPLACE(video_start_image, 'image_crop_resized=200x120', 'image_crop_resized=1200x680')
WHERE
	video_start_image LIKE '%image_crop_resized%';


ALTER IGNORE TABLE was_event_participant ADD UNIQUE (user_id,event_id);

ALTER TABLE was_event_user ADD COLUMN `data1` varchar(50) DEFAULT NULL AFTER event_id;

ALTER TABLE `wa_user_cc_data`  ADD `user_credit_card_id` INT UNSIGNED NULL DEFAULT NULL AFTER `user_id`;
