From 153f0a7ef84ed9630de4cbc4550d2fce6703b09c Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Fri, 13 Apr 2012 19:07:03 -0400
Subject: [PATCH] Fix SQL schema errors

---
 setup/inc/sql/02decaa2-60fcbee1.patch.sql |  4 ++--
 setup/inc/sql/60fcbee1-f8856d56.patch.sql | 21 +++++++++++++++------
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/setup/inc/sql/02decaa2-60fcbee1.patch.sql b/setup/inc/sql/02decaa2-60fcbee1.patch.sql
index 351bea582..40dc644b3 100644
--- a/setup/inc/sql/02decaa2-60fcbee1.patch.sql
+++ b/setup/inc/sql/02decaa2-60fcbee1.patch.sql
@@ -1,6 +1,6 @@
+-- Update all temlates with the new wording.
 UPDATE `%TABLE_PREFIX%email_template`
-    SET `overlimit_body` = '%name\r\n\r\nYou have reached the maximum number of open tickets allowed.\r\n\r\nTo be able to open another ticket, one of your pending tickets must be closed. To update or add comments to an open ticket simply login using the link below.\r\n\r\n%url/view.php?e=%email\r\n\r\nThank you.\r\n\r\nSupport Ticket System'
-    WHERE `tpl_id` = 1 AND `cfg_id` = 1;
+    SET `ticket_overlimit_body` = '%name\r\n\r\nYou have reached the maximum number of open tickets allowed.\r\n\r\nTo be able to open another ticket, one of your pending tickets must be closed. To update or add comments to an open ticket simply login using the link below.\r\n\r\n%url/view.php?e=%email\r\n\r\nThank you.\r\n\r\nSupport Ticket System';
 
 UPDATE `%TABLE_PREFIX%config`
     SET `schema_signature`='60fcbee1da3180d1b690187aa5006c88';
diff --git a/setup/inc/sql/60fcbee1-f8856d56.patch.sql b/setup/inc/sql/60fcbee1-f8856d56.patch.sql
index dcdb18502..2b7e48599 100644
--- a/setup/inc/sql/60fcbee1-f8856d56.patch.sql
+++ b/setup/inc/sql/60fcbee1-f8856d56.patch.sql
@@ -1,10 +1,19 @@
-ALTER TABLE `%TABLE_PREFIX%history`
-    ADD `staff_id` int(11) unsigned NOT NULL AFTER `ticket_id`,
-    ADD `team_id` int(11) unsigned NOT NULL AFTER `staff_id`,
-    ADD `dept_id` int(11) unsigned NOT NULL AFTER `team_id`,
-    ADD `topic_id` int(11) unsigned NOT NULL AFTER `dept_id`;
+DROP TABLE IF EXISTS `%TABLE_PREFIX%ticket_event`;
+CREATE TABLE `%TABLE_PREFIX%ticket_event` (
+  `ticket_id` int(11) unsigned NOT NULL default '0',
+  `staff_id` int(11) unsigned NOT NULL,
+  `team_id` int(11) unsigned NOT NULL,
+  `dept_id` int(11) unsigned NOT NULL,
+  `topic_id` int(11) unsigned NOT NULL,
+  `state` enum('created','closed','reopened','assigned','transferred','overdue') NOT NULL,
+  `staff` varchar(255) NOT NULL default 'SYSTEM',
+  `timestamp` datetime NOT NULL,
+  KEY `ticket_state` (`ticket_id`, `state`, `timestamp`),
+  KEY `ticket_stats` (`timestamp`, `state`)
+) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
-RENAME TABLE `%TABLE_PREFIX%history` TO `%TABLE_PREFIX%event`;
+DROP TABLE IF EXISTS `%TABLE_PREFIX%ticket_history`;
+DROP TABLE IF EXISTS `%TABLE_PREFIX%history`;
 
 UPDATE `%TABLE_PREFIX%config`
     SET `schema_signature`='f8856d56e51c5cc3416389de78b54515';
-- 
GitLab