From 9568ff487a856a16e636b8d7c196b3931c3b742b Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Mon, 7 Apr 2014 11:10:27 -0500 Subject: [PATCH] Fixup missing column in upgrades from < v1.8.0 There was a major goof for osTicket 1.8.0 where the installer created a `form_id` column in the `%filter` table; however, the upgrader neglected to add the column. Therefore, users who have upgraded from a version previous to 1.8.0 will not have the `form_id` column in their database whereas users who installed osTicket >= v1.8.0 and upgraded will have the column. Since MySQL has no concept of `ADD IF NOT EXISTS`, this dynamic query will assist with adding the column if it doesn't exist. Thanks, http://stackoverflow.com/a/16405301/1025836 --- .../streams/core/f5692e24-4323a6a8.patch.sql | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/upgrader/streams/core/f5692e24-4323a6a8.patch.sql b/include/upgrader/streams/core/f5692e24-4323a6a8.patch.sql index c3bc8ccc3..ee2296eb5 100644 --- a/include/upgrader/streams/core/f5692e24-4323a6a8.patch.sql +++ b/include/upgrader/streams/core/f5692e24-4323a6a8.patch.sql @@ -40,6 +40,26 @@ ALTER TABLE `%TABLE_PREFIX%faq_category` CHANGE `created` `created` datetime NOT NULL, CHANGE `updated` `updated` datetime NOT NULL; +-- There was a major goof for osTicket 1.8.0 where the installer created a +-- `form_id` column in the `%filter` table; however, the upgrader neglected +-- to add the column. Therefore, users who have upgraded from a version +-- previous to 1.8.0 will not have the `form_id` column in their database +-- whereas users who installed osTicket >= v1.8.0 and upgraded will have the +-- column. Since MySQL has no concept of `ADD COLUMN IF NOT EXISTS`, this +-- dynamic query will assist with adding the column if it doesn't exist. +SET @s = (SELECT IF( + (SELECT COUNT(*) + FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = '%TABLE_PREFIX%filter' + AND table_schema = DATABASE() + AND column_name = 'form_id' + ) > 0, + "SELECT 1", + "ALTER TABLE `%TABLE_PREFIX%filter` ADD `form_id` int(11) unsigned NOT NULL default '0' AFTER `sla_id`" +)); +PREPARE stmt FROM @s; +EXECUTE stmt; + ALTER TABLE `%TABLE_PREFIX%filter` ADD `topic_id` int(11) unsigned NOT NULL default '0' AFTER `form_id`; -- GitLab