DROP TABLE IF EXISTS `x_st2_datatrack_changelog`;
DROP TABLE IF EXISTS `x_st2_datatrack_log`;

CREATE TABLE `x_st2_datatrack_changelog` (
  `row_id` varchar(36) NOT NULL,
  `type` enum('insert','update','delete','error') NOT NULL,
  PRIMARY KEY (`row_id`),
  KEY `type` (`type`)
) ENGINE=MyISAM COMMENT='Have to be MyISAM!';

CREATE TABLE `x_st2_datatrack_log` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `type` enum('insert','update','delete','reset','touch') NOT NULL,
  `row_id` varchar(36) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `type` (`type`),
  KEY `row_id` (`row_id`)
) ENGINE=InnoDB;

INSERT INTO `x_st2_datatrack_log` (`id`, `type`, `row_id`) VALUES
(17649333,	'insert',	'571305'),
(17649334,	'update',	'571305'),
(17649337,	'update',	'545271'),
(17649338,	'update',	'4961'),
(17649339,	'update',	'4991'),
(17649340,	'update',	'5001');


/*
CREATE TRIGGER `x_st2_datatrack_changelog_bi` BEFORE INSERT ON `x_st2_datatrack_changelog` FOR EACH ROW
BEGIN
END;
*/


INSERT INTO `x_st2_datatrack_changelog`
  (`row_id`, `type`)

SELECT `row_id`, `type`
FROM `x_st2_datatrack_log`
ORDER BY `id`

ON DUPLICATE KEY UPDATE
  `type`=VALUES(`type`);
  
SHOW WARNINGS;  


SELECT * FROM `x_st2_datatrack_changelog`;
