diff --git a/include/upgrader/streams/core/0d6099a6-98ad7d55.patch.sql b/include/upgrader/streams/core/0d6099a6-98ad7d55.patch.sql index be6707ec63dc7f673ecb7c5f3373eb07cbd75812..e6a054535316800e3a97ab3ab0cadd03c2fbb282 100644 --- a/include/upgrader/streams/core/0d6099a6-98ad7d55.patch.sql +++ b/include/upgrader/streams/core/0d6099a6-98ad7d55.patch.sql @@ -33,9 +33,6 @@ ALTER TABLE `%TABLE_PREFIX%staff` ALTER TABLE `%TABLE_PREFIX%team_member` ADD `flags` int(10) unsigned NOT NULL DEFAULT 1 AFTER `staff_id`; -ALTER TABLE `%TABLE_PREFIX%thread_collaborator` - ADD KEY `user_id` (`user_id`); - ALTER TABLE `%TABLE_PREFIX%task` ADD `closed` datetime DEFAULT NULL AFTER `duedate`; diff --git a/include/upgrader/streams/core/2d590ffa-9143a511.patch.sql b/include/upgrader/streams/core/2d590ffa-9143a511.patch.sql index 4244e3bd590ea4c8f44fe131bed41748432e4095..5ffa7338516c054605d5e4ca0e1a7c10578ebca9 100644 --- a/include/upgrader/streams/core/2d590ffa-9143a511.patch.sql +++ b/include/upgrader/streams/core/2d590ffa-9143a511.patch.sql @@ -23,40 +23,33 @@ ALTER TABLE `%TABLE_PREFIX%lock` -- Drop all the current locks as they do not point to anything now TRUNCATE TABLE `%TABLE_PREFIX%lock`; -RENAME TABLE `%TABLE_PREFIX%ticket_collaborator` TO `%TABLE_PREFIX%thread_collaborator`; -ALTER TABLE `%TABLE_PREFIX%thread_collaborator` - CHANGE `ticket_id` `thread_id` int(11) unsigned NOT NULL DEFAULT '0'; - -UPDATE `%TABLE_PREFIX%thread_collaborator` t1 - LEFT JOIN `%TABLE_PREFIX%thread` t2 ON (t2.object_id = t1.thread_id and t2.object_type = 'T') - SET t1.thread_id = t2.id, t1.created = t2.created; +CREATE TABLE `%TABLE_PREFIX%thread_collaborator` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `isactive` tinyint(1) NOT NULL DEFAULT '1', + `thread_id` int(11) unsigned NOT NULL DEFAULT '0', + `user_id` int(11) unsigned NOT NULL DEFAULT '0', + -- M => (message) clients, N => (note) 3rd-Party, R => (reply) external authority + `role` char(1) NOT NULL DEFAULT 'M', + `created` datetime NOT NULL, + `updated` datetime NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `collab` (`thread_id`,`user_id`), + KEY `user_id` (`user_id`) +) DEFAULT CHARSET=utf8; -- Drop zombie collaborators from tickets which were deleted and had -- collaborators and the collaborators were not removed -DELETE A1.* - FROM `%TABLE_PREFIX%thread_collaborator` A1 - LEFT JOIN `%TABLE_PREFIX%thread` A2 ON (A2.id = A1.thread_id) - WHERE A2.id IS NULL; +INSERT INTO `%TABLE_PREFIX%thread_collaborator` + (`id`, `isactive`, `thread_id`, `user_id`, `role`, `created`, `updated`) + SELECT t1.`id`, t1.`isactive`, t2.`id`, t1.`user_id`, t1.`role`, t2.`created`, t1.`updated` + FROM `%TABLE_PREFIX%ticket_collaborator` t1 + JOIN `%TABLE_PREFIX%thread` t2 ON (t2.`object_id` = t1.`ticket_id` and t2.`object_type` = 'T'); + +DROP TABLE `%TABLE_PREFIX%ticket_collaborator`; ALTER TABLE `%TABLE_PREFIX%task` ADD `lock_id` int(11) unsigned NOT NULL DEFAULT '0' AFTER `team_id`; -ALTER TABLE `%TABLE_PREFIX%thread_entry` - ADD `flags` int(11) unsigned NOT NULL default '0' AFTER `type`; - --- Set the ORIGINAL_MESSAGE flag to all the first messages of each thread -CREATE TABLE `%TABLE_PREFIX%_orig_msg_ids` - (id INT NOT NULL, PRIMARY KEY (id)) - SELECT min(id) as id FROM `%TABLE_PREFIX%thread_entry` - WHERE type = 'M' - GROUP BY thread_id; - -UPDATE `%TABLE_PREFIX%thread_entry` A1 - JOIN `%TABLE_PREFIX%_orig_msg_ids` A2 ON (A1.id = A2.id) - SET A1.`flags` = 1 ; - -DROP TABLE `%TABLE_PREFIX%_orig_msg_ids`; - -- Finished with patch UPDATE `%TABLE_PREFIX%config` SET `value` = '9143a511719555e8f8f09b49523bd022' diff --git a/include/upgrader/streams/core/36f6b328-5cd0a25a.cleanup.sql b/include/upgrader/streams/core/36f6b328-5cd0a25a.cleanup.sql index 533991fb497d35e870ebcaf454475c6c45653c09..3c93133c12d95e9d8699f8cc5870b30dd69e0324 100644 --- a/include/upgrader/streams/core/36f6b328-5cd0a25a.cleanup.sql +++ b/include/upgrader/streams/core/36f6b328-5cd0a25a.cleanup.sql @@ -19,4 +19,3 @@ DROP TABLE `%TABLE_PREFIX%ticket_attachment`; OPTIMIZE TABLE `%TABLE_PREFIX%ticket`; OPTIMIZE TABLE `%TABLE_PREFIX%thread`; -OPTIMIZE TABLE `%TABLE_PREFIX%thread_entry`; diff --git a/include/upgrader/streams/core/36f6b328-5cd0a25a.patch.sql b/include/upgrader/streams/core/36f6b328-5cd0a25a.patch.sql index e20f60e8bf09640416ec3ca35821dc3f1d232425..47a74b05e9c653b1a01e3a654be33728aa19283e 100644 --- a/include/upgrader/streams/core/36f6b328-5cd0a25a.patch.sql +++ b/include/upgrader/streams/core/36f6b328-5cd0a25a.patch.sql @@ -34,20 +34,53 @@ INSERT INTO `%TABLE_PREFIX%thread` ON (t1.ticket_id=t2.ticket_id and t1.id=t2.id) ORDER BY t1.created; -ALTER TABLE `%TABLE_PREFIX%ticket_thread` - ADD `thread_id` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `pid` , - ADD INDEX ( `thread_id` ); - -UPDATE `%TABLE_PREFIX%ticket_thread` t1 - LEFT JOIN `%TABLE_PREFIX%thread` t2 ON ( t2.object_id = t1.ticket_id ) - SET t1.thread_id = t2.id; - -- convert ticket_thread to thread_entry -ALTER TABLE `%TABLE_PREFIX%ticket_thread` - CHANGE `thread_type` `type` CHAR( 1 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, - ADD INDEX ( `type` ); +CREATE TABLE `%TABLE_PREFIX%thread_entry` ( + `id` int(11) unsigned NOT NULL auto_increment, + `pid` int(11) unsigned NOT NULL default '0', + `thread_id` int(11) unsigned NOT NULL default '0', + `staff_id` int(11) unsigned NOT NULL default '0', + `user_id` int(11) unsigned not null default 0, + `type` char(1) NOT NULL default '', + `flags` int(11) unsigned NOT NULL default '0', + `poster` varchar(128) NOT NULL default '', + `editor` int(10) unsigned NULL, + `editor_type` char(1) NULL, + `source` varchar(32) NOT NULL default '', + `title` varchar(255), + `body` text NOT NULL, + `format` varchar(16) NOT NULL default 'html', + `ip_address` varchar(64) NOT NULL default '', + `created` datetime NOT NULL, + `updated` datetime NOT NULL, + PRIMARY KEY (`id`), + KEY `pid` (`pid`), + KEY `thread_id` (`thread_id`), + KEY `staff_id` (`staff_id`), + KEY `type` (`type`) +) DEFAULT CHARSET=utf8; -RENAME TABLE `%TABLE_PREFIX%ticket_thread` TO `%TABLE_PREFIX%thread_entry` ; +-- Set the ORIGINAL_MESSAGE flag to all the first messages of each thread +CREATE TABLE `%TABLE_PREFIX%_orig_msg_ids` + (`id` INT NOT NULL, PRIMARY KEY (id)) + SELECT MIN(id) AS `id` FROM `%TABLE_PREFIX%ticket_thread` + WHERE `thread_type` = 'M' + GROUP BY `ticket_id`; + +INSERT INTO `%TABLE_PREFIX%thread_entry` + (`id`, `pid`, `thread_id`, `staff_id`, `user_id`, `type`, `flags`, + `poster`, `source`, `title`, `body`, `format`, `ip_address`, `created`, + `updated`) + SELECT t1.`id`, t1.`pid`, t2.`id`, t1.`staff_id`, t1.`user_id`, t1.`thread_type`, + CASE WHEN t3.`id` IS NULL THEN 0 ELSE 1 END, + t1.`poster`, t1.`source`, t1.`title`, t1.`body`, t1.`format`, t1.`ip_address`, + t1.`created`, t1.`updated` + FROM `%TABLE_PREFIX%ticket_thread` t1 + LEFT JOIN `%TABLE_PREFIX%thread` t2 ON (t2.object_id = t1.ticket_id AND t2.object_type = 'T') + LEFT JOIN `%TABLE_PREFIX%_orig_msg_ids` t3 ON (t1.id = t3.id); + +DROP TABLE `%TABLE_PREFIX%ticket_thread`; +DROP TABLE `%TABLE_PREFIX%_orig_msg_ids`; -- add thread id to ticket table ALTER TABLE `%TABLE_PREFIX%ticket` diff --git a/include/upgrader/streams/core/9143a511-0d6099a6.patch.sql b/include/upgrader/streams/core/9143a511-0d6099a6.patch.sql index c6bf19b42ba79cfde7f076d9b7b056856d0a0b55..d5a151c9ec7ba6d8f686347d492387130a773a9d 100644 --- a/include/upgrader/streams/core/9143a511-0d6099a6.patch.sql +++ b/include/upgrader/streams/core/9143a511-0d6099a6.patch.sql @@ -36,10 +36,6 @@ UPDATE `%TABLE_PREFIX%thread_event` A1 ALTER TABLE `%TABLE_PREFIX%user_email` ADD `flags` int(10) unsigned NOT NULL DEFAULT 0 AFTER `user_id`; -ALTER TABLE `%TABLE_PREFIX%thread_entry` - ADD `editor` int(10) unsigned NULL AFTER `poster`, - ADD `editor_type` char(1) NULL AFTER `editor`; - ALTER TABLE `%TABLE_PREFIX%form` CHANGE `deletable` `flags` int(10) unsigned NOT NULL DEFAULT 1;