From 2fba839e8b3a540e7e74493b63f7833a505da5f2 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 26 Jun 2015 10:17:07 -0400 Subject: [PATCH] Add Servers Table and add Id PRIMARY KEY to States --- db/zm_create.sql.in | 14 +++++++++++++- db/zm_update-1.28.99.sql | 31 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index c7d51641c..8df9e7a3b 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -386,11 +386,23 @@ CREATE TABLE `Monitors` ( DROP TABLE IF EXISTS `States`; CREATE TABLE `States` ( + `Id` int(10) unsigned NOT NULL auto_increment,, `Name` varchar(64) NOT NULL default '', `Definition` text NOT NULL, - PRIMARY KEY (`Name`) + PRIMARY KEY (`Id`) ) ENGINE=@ZM_MYSQL_ENGINE@; +-- +-- Table structure for table `Servers` +-- + +DROP TABLE IF EXISTS `Servers`; +CREATE TABLE `Servers` ( + `Id` int(10) unsigned NOT NULL auto_increment, + `Name` varchar(64) NOT NULL default '', + `State_Id` int(10) unsigned, + PRIMARY KEY (`Id`) +) ENGINE=@ZM_MYSQL_ENGINE@; -- -- Table structure for table `Stats` -- diff --git a/db/zm_update-1.28.99.sql b/db/zm_update-1.28.99.sql index 3aab54345..2e1802966 100644 --- a/db/zm_update-1.28.99.sql +++ b/db/zm_update-1.28.99.sql @@ -324,4 +324,35 @@ WHERE NOT EXISTS ( -- UPDATE `zm`.`Config` SET `Category`='hidden' WHERE `Name`='ZM_USE_DEEP_STORAGE'; +-- +-- Add Id column to State +-- +SET @s = (SELECT IF( + (SELECT COUNT(*) + FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'States' + AND table_schema = DATABASE() + AND column_name = 'Id' + ) > 0, +"SELECT 'Column Id exists in States'", +"ALTER TABLE States ALTER Name DROP PRIMARY KEY;ALTER TABLE `States` ADD `Id` int(10) unsigned auto_increment NOT NULL PRIMARY KEY FIRST" +)); + +PREPARE stmt FROM @s; +EXECUTE stmt; + +SET @s = (SELECT IF( + (SELECT COUNT(*) + FROM INFORMATION_SCHEMA.TABLES + WHERE table_name = 'Servers' + AND table_schema = DATABASE() + ) > 0, +"SELECT 'Servers table exists'", +"CREATE TABLE `Servers` ( + `Id` int(10) unsigned NOT NULL auto_increment, + `Name` varchar(64) NOT NULL default '', + `State_Id` int(10) unsigned, + PRIMARY KEY (`Id`) +)" +));