
CREATE TABLE `was_event_user` (
  `event_user_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` int(11) unsigned NOT NULL,
  `data1` varchar(50) DEFAULT NULL,
  `user_id` int(11) unsigned NOT NULL,
  `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_user_id`),
  KEY `idx_event_id` (`event_id`),
  KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB COMMENT='Store users that join using Class';

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


CREATE TABLE `was_event_stats` (
  `event_stats_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` int(11) unsigned NOT NULL,
  `comment_count` int(11) unsigned NOT NULL,
  `like_count` int(11) unsigned NOT NULL,
  `signup_count` int(11) unsigned NOT NULL,
  `upgrade_count` int(11) unsigned NOT NULL,
  `revenue` decimal(9,2) NOT NULL DEFAULT '0.00',
  `unique_view_count` int(11) unsigned NOT NULL,
  `unique_mobile_count` int(11) unsigned NOT NULL,
  `unique_desktop_count` int(11) unsigned NOT NULL,
  `raw_view_count` int(11) unsigned NOT NULL,
  `raw_mobile_count` int(11) unsigned NOT NULL,
  `raw_desktop_count` int(11) unsigned NOT NULL,
  `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_stats_id`),
  KEY `idx_event_id` (`event_id`)
) ENGINE=InnoDB COMMENT='Store class stats';

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


CREATE TABLE `was_event_stats_day` (
  `event_stats_day_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` int(11) unsigned NOT NULL,
  `stats_day` date NOT NULL DEFAULT '0000-00-00',
  `signup_count` int(11) unsigned NOT NULL DEFAULT '0',
  `upgrade_count` int(11) unsigned NOT NULL DEFAULT '0',
  `revenue` decimal(9,2) NOT NULL DEFAULT '0.00',
  `unique_view_count` int(11) unsigned NOT NULL DEFAULT '0',
  `unique_mobile_count` int(11) unsigned NOT NULL DEFAULT '0',
  `unique_desktop_count` int(11) unsigned NOT NULL DEFAULT '0',
  `raw_view_count` int(11) unsigned NOT NULL DEFAULT '0',
  `raw_desktop_count` int(11) unsigned NOT NULL DEFAULT '0',
  `raw_mobile_count` int(11) unsigned NOT NULL DEFAULT '0',
  `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_stats_day_id`),
  KEY `idx_event_stats` (`event_id`,`stats_day`)
) ENGINE=InnoDB COMMENT='Store daily class stats data';

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


CREATE TABLE `was_event_stats_raw` (
  `event_stats_raw_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` int(11) unsigned NOT NULL,
  `user_id` int(11) unsigned DEFAULT NULL,
  `ip_address` varchar(46) DEFAULT NULL,
  `stats_type` tinyint(1) unsigned NOT NULL,
  `stats_data` TEXT NOT NULL COMMENT 'Additional data related to the stats event',
  `stats_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `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_stats_raw_id`),
  KEY `idx_event_id` (`event_id`),
  KEY `idx_event_ip_address` (`ip_address`,`stats_type`,`stats_timestamp`)
) ENGINE=InnoDB COMMENT='Store class raw stats';

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

CREATE TABLE `was_event_share_stats` (
  `event_share_stats_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` int(11) unsigned NOT NULL,
  `data1` varchar(50) DEFAULT NULL,
  `signup_count` int(11) unsigned NOT NULL,
  `upgrade_count` int(11) unsigned NOT NULL,
  `revenue` decimal(9,2) NOT NULL DEFAULT '0.00',
  `unique_view_count` int(11) unsigned NOT NULL,
  `unique_mobile_count` int(11) unsigned NOT NULL,
  `unique_desktop_count` int(11) unsigned NOT NULL,
  `raw_view_count` int(11) unsigned NOT NULL,
  `raw_mobile_count` int(11) unsigned NOT NULL,
  `raw_desktop_count` int(11) unsigned NOT NULL,
  `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_share_stats_id`),
  KEY `idx_event_data` (`event_id`,`data1`)
) ENGINE=InnoDB COMMENT='Store class share stats';

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


CREATE TABLE `was_event_share_stats_day` (
  `event_share_stats_day_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` int(11) unsigned NOT NULL,
  `data1` varchar(50) DEFAULT NULL,
  `stats_day` date NOT NULL DEFAULT '0000-00-00',
  `signup_count` int(11) unsigned NOT NULL DEFAULT '0',
  `upgrade_count` int(11) unsigned NOT NULL DEFAULT '0',
  `revenue` decimal(9,2) NOT NULL DEFAULT '0.00',
  `unique_view_count` int(11) unsigned NOT NULL DEFAULT '0',
  `unique_mobile_count` int(11) unsigned NOT NULL DEFAULT '0',
  `unique_desktop_count` int(11) unsigned NOT NULL DEFAULT '0',
  `raw_view_count` int(11) unsigned NOT NULL DEFAULT '0',
  `raw_desktop_count` int(11) unsigned NOT NULL DEFAULT '0',
  `raw_mobile_count` int(11) unsigned NOT NULL DEFAULT '0',
  `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_share_stats_day_id`),
  KEY `idx_event_stats` (`event_id`,`data1`,`stats_day`)
) ENGINE=InnoDB COMMENT='Store daily class share stats data';

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


CREATE TABLE `was_event_share_stats_raw` (
  `event_share_stats_raw_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` int(11) unsigned NOT NULL,
  `data1` varchar(50) DEFAULT NULL,
  `user_id` int(11) unsigned DEFAULT NULL,
  `ip_address` varchar(46) DEFAULT NULL,
  `stats_type` tinyint(1) unsigned NOT NULL,
  `stats_data` TEXT NOT NULL COMMENT 'Additional data related to the stats event',
  `stats_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `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_share_stats_raw_id`),
  KEY `idx_event_data` (`event_id`,`data1`),
  KEY `idx_event_ip_address` (`ip_address`,`stats_type`,`stats_timestamp`)
) ENGINE=InnoDB COMMENT='Store class share raw stats';

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

