From b18ffdc13e1069186376e8a0841934e5732c98e6 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Wed, 26 Aug 2015 11:20:22 -0400 Subject: [PATCH] States table updated to unique Name column --- db/zm_update-1.28.99.sql | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/db/zm_update-1.28.99.sql b/db/zm_update-1.28.99.sql index 3ddd0c77d..6e1313ba3 100644 --- a/db/zm_update-1.28.99.sql +++ b/db/zm_update-1.28.99.sql @@ -342,7 +342,7 @@ SET @s = (SELECT IF( PREPARE stmt FROM @s; EXECUTE stmt; --- The States table will be updated to have a new column called IsActive +-- PP:The States table will be updated to have a new column called IsActive -- used to keep track of which custom state is active (if any) SET @s = (SELECT IF( (SELECT COUNT(*) @@ -358,6 +358,23 @@ SET @s = (SELECT IF( PREPARE stmt FROM @s; EXECUTE stmt; +-- PP:If default state does not exist, create it and set its IsActive to 1 +INSERT INTO States (Name,Definition,IsActive) + SELECT * FROM (SELECT 'default', '', '1') AS tmp + WHERE NOT EXISTS ( + SELECT Name FROM States WHERE Name = 'default' + ) LIMIT 1; + +-- PP:Start with a sane isActive state +UPDATE States SET IsActive = '0'; +UPDATE States SET IsActive = '1' WHERE Name = 'default'; + +-- PP:Finally convert States to make sure Names are unique +-- If duplicate states existed while upgrading, that is +-- very likely an error that ZM allowed earlier, so +-- we are picking up the first one and deleting the others +ALTER IGNORE TABLE States ADD UNIQUE (Name); + SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES