CREATE TABLE `was_event_stats_hour` (
 `event_stats_hour_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
 `event_id` int(11) unsigned NOT NULL,
 `stats_day` date NOT NULL DEFAULT '0000-00-00',
 `stats_hour` int(11) unsigned NOT NULL,
 `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_hour_id`),
 KEY `idx_event_stats_hour` (`event_id`,`stats_day`,`stats_hour`)
) ENGINE=InnoDB COMMENT='Store hourly class stats data';

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


CREATE TABLE `was_event_share_stats_hour` (
 `event_share_stats_hour_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',
 `stats_hour` int(11) unsigned NOT NULL,
 `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_hour_id`),
 KEY `idx_event_share_stats_hour` (`event_id`,`stats_day`,`stats_hour`)
) ENGINE=InnoDB COMMENT='Store hourly class share stats data';

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


CREATE TABLE `was_event_revenue_stats_hour` (
  `event_revenue_stats_hour_id` int(11) NOT NULL AUTO_INCREMENT,
  `event_id` int(11) NOT NULL,
  `revenue` decimal(9,2) NOT NULL DEFAULT '0.00',
  `stats_day` date NOT NULL DEFAULT '0000-00-00',
  `stats_hour` int(11) unsigned NOT NULL,
  `billing` enum('Monthly','Yearly') 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_revenue_stats_hour_id`),
  KEY `idx_event_stats_revenue_hour` (`event_id`,`stats_day`,`stats_hour`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

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


CREATE TABLE `was_event_share_revenue_stats_hour` (
  `event_share_revenue_stats_hour_id` int(11) NOT NULL AUTO_INCREMENT,
  `event_id` int(11) NOT NULL,
  `data1` varchar(50) DEFAULT NULL,
  `revenue` decimal(9,2) NOT NULL DEFAULT '0.00',
  `billing` enum('Monthly','Yearly') NOT NULL,
  `stats_day` date NOT NULL DEFAULT '0000-00-00',
  `stats_hour` 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_revenue_stats_hour_id`),
  KEY `idx_event_share_stats_revenue_hour` (`event_id`,`stats_day`,`stats_hour`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

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