States table updated to unique Name column

This commit is contained in:
Pliable Pixels 2015-08-26 11:20:22 -04:00
parent 82fe6c8f0e
commit b18ffdc13e
1 changed files with 18 additions and 1 deletions

View File

@ -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