
CREATE TABLE `was_training_core` (
  `training_core_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `training_title` varchar(255) NOT NULL,
  `training_order` int(11) NOT NULL,
  `series_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 (`training_core_id`),
  KEY `idx_series_id` (`series_id`),
  KEY `idx_training_order` (`training_order`)
) ENGINE=InnoDB;

CREATE TABLE `was_training_category` (
  `training_category_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `item_category_id` int(11) unsigned NOT NULL,
  `series_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 (`training_category_id`),
  KEY `idx_item_category_id` (`item_category_id`),
  KEY `idx_series_id` (`series_id`)
) ENGINE=InnoDB;

CREATE TABLE `wap_training_complete` (
  `training_complete_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `resource_id` int(11) unsigned NOT 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 (`training_complete_id`),
  KEY `idx_resource_id` (`resource_id`),
  KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB;


CREATE TRIGGER `was_training_core_insert_timestamp` BEFORE INSERT ON `was_training_core` FOR EACH ROW SET NEW.insert_timestamp = NOW();
CREATE TRIGGER `was_training_category_insert_timestamp` BEFORE INSERT ON `was_training_category` FOR EACH ROW SET NEW.insert_timestamp = NOW();
CREATE TRIGGER `wap_training_complete_insert_timestamp` BEFORE INSERT ON `wap_training_complete` FOR EACH ROW SET NEW.insert_timestamp = NOW();

INSERT INTO was_training_category (item_category_id, series_id) SELECT item_category_id, series_id FROM was_item_category_training;
INSERT INTO wap_training_complete (resource_id, user_id) SELECT class_id AS resource_id, user_id FROM was_item_category_training_tracking;

DROP TABLE was_item_category_training;
DROP TABLE was_item_category_training_tracking;