2017-07-12 02:11:15 +08:00
|
|
|
--
|
|
|
|
-- This adds StorageAreas
|
|
|
|
--
|
|
|
|
|
2018-01-20 05:32:48 +08:00
|
|
|
SELECT 'Checking For Storage Table';
|
2017-07-12 02:11:15 +08:00
|
|
|
SET @s = (SELECT IF(
|
|
|
|
(SELECT COUNT(*)
|
|
|
|
FROM INFORMATION_SCHEMA.TABLES
|
|
|
|
WHERE table_name = 'Storage'
|
|
|
|
AND table_schema = DATABASE()
|
|
|
|
) > 0,
|
|
|
|
"SELECT 'Storage table exists'",
|
|
|
|
"CREATE TABLE `Storage` (
|
|
|
|
`Id` smallint(5) unsigned NOT NULL auto_increment,
|
|
|
|
`Path` varchar(64) NOT NULL default '',
|
|
|
|
`Name` varchar(64) NOT NULL default '',
|
|
|
|
PRIMARY KEY (`Id`)
|
|
|
|
)"
|
|
|
|
));
|
|
|
|
|
|
|
|
PREPARE stmt FROM @s;
|
|
|
|
EXECUTE stmt;
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Add StorageId column to Monitors
|
|
|
|
--
|
|
|
|
|
2018-01-20 05:32:48 +08:00
|
|
|
SELECT 'Checking For StorageId in Monitors';
|
2017-07-12 02:11:15 +08:00
|
|
|
SET @s = (SELECT IF(
|
|
|
|
(SELECT COUNT(*)
|
|
|
|
FROM INFORMATION_SCHEMA.COLUMNS
|
|
|
|
WHERE table_name = 'Monitors'
|
|
|
|
AND table_schema = DATABASE()
|
|
|
|
AND column_name = 'StorageId'
|
|
|
|
) > 0,
|
|
|
|
"SELECT 'Column StorageId exists in Monitors'",
|
|
|
|
"ALTER TABLE Monitors ADD `StorageId` smallint(5) unsigned NOT NULL default 0 AFTER `ServerId`"
|
|
|
|
));
|
|
|
|
|
|
|
|
PREPARE stmt FROM @s;
|
|
|
|
EXECUTE stmt;
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Add StorageId column to Eventss
|
|
|
|
--
|
|
|
|
|
2018-01-20 05:32:48 +08:00
|
|
|
SELECT 'Checking For StorageId in Events';
|
2017-07-12 02:11:15 +08:00
|
|
|
SET @s = (SELECT IF(
|
|
|
|
(SELECT COUNT(*)
|
|
|
|
FROM INFORMATION_SCHEMA.COLUMNS
|
|
|
|
WHERE table_name = 'Events'
|
|
|
|
AND table_schema = DATABASE()
|
|
|
|
AND column_name = 'StorageId'
|
|
|
|
) > 0,
|
|
|
|
"SELECT 'Column StorageId exists in Events'",
|
|
|
|
"ALTER TABLE Events ADD `StorageId` smallint(5) unsigned NOT NULL default 0 AFTER `MonitorId`"
|
|
|
|
));
|
|
|
|
|
|
|
|
PREPARE stmt FROM @s;
|
|
|
|
EXECUTE stmt;
|
|
|
|
|
2018-01-20 05:32:48 +08:00
|
|
|
SELECT 'Updating Monitors SETTING StorageId to default';
|
2017-07-12 02:11:15 +08:00
|
|
|
UPDATE Monitors SET StorageId = 0 WHERE StorageId IS NULL;
|
|
|
|
ALTER TABLE Monitors MODIFY `StorageId` smallint(5) unsigned NOT NULL default 0;
|
|
|
|
UPDATE Events SET StorageId = 0 WHERE StorageId IS NULL;
|
|
|
|
ALTER TABLE Events MODIFY `StorageId` smallint(5) unsigned NOT NULL default 0;
|
2017-07-12 02:31:41 +08:00
|
|
|
|
|
|
|
SET @s = (SELECT IF(
|
|
|
|
(SELECT COUNT(*)
|
|
|
|
FROM INFORMATION_SCHEMA.COLUMNS
|
|
|
|
WHERE table_name = 'Events'
|
|
|
|
AND table_schema = DATABASE()
|
|
|
|
AND column_name = 'Orientation'
|
|
|
|
) > 0,
|
|
|
|
"SELECT 'Column Orientation exists in Events'",
|
|
|
|
"ALTER TABLE `Events` ADD `Orientation` enum('0','90','180','270','hori','vert') NOT NULL default '0' AFTER `Notes`"
|
|
|
|
));
|
|
|
|
|
|
|
|
PREPARE stmt FROM @s;
|
|
|
|
EXECUTE stmt;
|
2017-07-12 08:33:09 +08:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Update Monitors table to have an Index on ServerId
|
|
|
|
--
|
2018-01-20 05:32:48 +08:00
|
|
|
SELECT 'Create Index For ServerId on Monitors';
|
2017-07-12 08:33:09 +08:00
|
|
|
SET @s = (SELECT IF(
|
|
|
|
(SELECT COUNT(*)
|
|
|
|
FROM INFORMATION_SCHEMA.STATISTICS
|
|
|
|
WHERE table_name = 'Monitors'
|
|
|
|
AND table_schema = DATABASE()
|
|
|
|
AND index_name = 'Monitors_ServerId_idx'
|
|
|
|
) > 0,
|
|
|
|
"SELECT 'Monitors_ServerId Index already exists on Monitors table'",
|
|
|
|
"CREATE INDEX `Monitors_ServerId_idx` ON `Monitors` (`ServerId`)"
|
|
|
|
));
|
|
|
|
|
|
|
|
PREPARE stmt FROM @s;
|
|
|
|
EXECUTE stmt;
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Update Server table to have an Index on Name
|
|
|
|
--
|
2018-01-20 05:32:48 +08:00
|
|
|
SELECT 'Create Index FOR Name on Servers';
|
2017-07-12 08:33:09 +08:00
|
|
|
SET @s = (SELECT IF(
|
|
|
|
(SELECT COUNT(*)
|
|
|
|
FROM INFORMATION_SCHEMA.STATISTICS
|
|
|
|
WHERE table_name = 'Servers'
|
|
|
|
AND table_schema = DATABASE()
|
|
|
|
AND index_name = 'Servers_Name_idx'
|
|
|
|
) > 0,
|
|
|
|
"SELECT 'Servers_Name Index already exists on Servers table'",
|
|
|
|
"CREATE INDEX `Servers_Name_idx` ON `Servers` (`Name`)"
|
|
|
|
));
|
|
|
|
|
|
|
|
PREPARE stmt FROM @s;
|
|
|
|
EXECUTE stmt;
|
|
|
|
|
2017-07-12 08:34:06 +08:00
|
|
|
|
2018-01-20 05:32:48 +08:00
|
|
|
SELECT 'ALTER TABLE Logs MODIFY Message TEXT NOT NULL';
|
2017-07-12 08:34:06 +08:00
|
|
|
-- ALTER TABLE Logs ALTER Message DROP DEFAULT;
|
|
|
|
ALTER TABLE Logs MODIFY Message TEXT NOT NULL;
|
|
|
|
|
2018-01-20 05:32:48 +08:00
|
|
|
SELECT 'ALTER TABLE Config MODIFY DefaultValue TEXT';
|
2017-07-12 08:34:06 +08:00
|
|
|
ALTER TABLE Config MODIFY DefaultValue TEXT;
|
|
|
|
|
2017-07-12 08:35:56 +08:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Add an Id column and make it the primary key of the Filters table
|
|
|
|
--
|
2018-01-20 05:32:48 +08:00
|
|
|
|
|
|
|
SELECT 'Check for Id column in Filter';
|
2017-07-12 08:35:56 +08:00
|
|
|
SET @s = (SELECT IF(
|
|
|
|
(SELECT COUNT(*)
|
|
|
|
FROM INFORMATION_SCHEMA.COLUMNS
|
|
|
|
WHERE table_name = 'Filters'
|
|
|
|
AND table_schema = DATABASE()
|
|
|
|
AND column_name = 'Id'
|
|
|
|
) > 0,
|
|
|
|
"SELECT 'Column Id exists in Filters'",
|
|
|
|
"ALTER TABLE `Filters` DROP PRIMARY KEY, ADD `Id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY FIRST, ADD KEY `Name` (`Name`);"
|
|
|
|
));
|
|
|
|
|
|
|
|
PREPARE stmt FROM @s;
|
|
|
|
EXECUTE stmt;
|
|
|
|
|