

CREATE TABLE `was_wistia_video_watch` (
  `wistia_video_watch_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(11) unsigned NOT NULL,
  `hashed_id` varchar(16) NOT NULL COMMENT 'hashed ID of the video',
  `position` smallint(11) unsigned NOT NULL COMMENT 'current time of the video in seconds',
  `duration` smallint(11) unsigned NOT NULL COMMENT 'duration of the video in seconds',
  `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 (`wistia_video_watch_id`),
  UNIQUE KEY `unq_user_wistia_hash` (`user_id`, `hashed_id`)
) ENGINE=InnoDB COMMENT='Stores current time & duration of the wistia video for a user';

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