Add primary keys to Logs and Stats tables (#2653)
* Add primary keys to Logs and Stats tables Adds an auto_increment int(10) Id as PRIMARY KEY to Logs and Stats tables. Closes ZoneMinder#2550 and makes ZoneMinder compatible with Galera writeset replication for InnoDB (Galera Cluster, Percona XtraDB Cluster). * Do ALTER TABLE only if columns do not exist * Add forgotten prepare/execute
This commit is contained in:
parent
2470c09b20
commit
aa817adbed
|
@ -351,6 +351,7 @@ CREATE INDEX `Groups_Monitors_MonitorId_idx` ON `Groups_Monitors` (`MonitorId`);
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `Logs`;
|
DROP TABLE IF EXISTS `Logs`;
|
||||||
CREATE TABLE `Logs` (
|
CREATE TABLE `Logs` (
|
||||||
|
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`TimeKey` decimal(16,6) NOT NULL,
|
`TimeKey` decimal(16,6) NOT NULL,
|
||||||
`Component` varchar(32) NOT NULL,
|
`Component` varchar(32) NOT NULL,
|
||||||
`ServerId` int(10) unsigned,
|
`ServerId` int(10) unsigned,
|
||||||
|
@ -360,6 +361,7 @@ CREATE TABLE `Logs` (
|
||||||
`Message` text NOT NULL,
|
`Message` text NOT NULL,
|
||||||
`File` varchar(255) DEFAULT NULL,
|
`File` varchar(255) DEFAULT NULL,
|
||||||
`Line` smallint(5) unsigned DEFAULT NULL,
|
`Line` smallint(5) unsigned DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`Id`),
|
||||||
KEY `TimeKey` (`TimeKey`)
|
KEY `TimeKey` (`TimeKey`)
|
||||||
) ENGINE=@ZM_MYSQL_ENGINE@;
|
) ENGINE=@ZM_MYSQL_ENGINE@;
|
||||||
|
|
||||||
|
@ -589,6 +591,7 @@ CREATE INDEX `Servers_Name_idx` ON `Servers` (`Name`);
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `Stats`;
|
DROP TABLE IF EXISTS `Stats`;
|
||||||
CREATE TABLE `Stats` (
|
CREATE TABLE `Stats` (
|
||||||
|
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`MonitorId` int(10) unsigned NOT NULL default '0',
|
`MonitorId` int(10) unsigned NOT NULL default '0',
|
||||||
`ZoneId` int(10) unsigned NOT NULL default '0',
|
`ZoneId` int(10) unsigned NOT NULL default '0',
|
||||||
`EventId` BIGINT UNSIGNED NOT NULL,
|
`EventId` BIGINT UNSIGNED NOT NULL,
|
||||||
|
@ -605,6 +608,7 @@ CREATE TABLE `Stats` (
|
||||||
`MinY` smallint(5) unsigned NOT NULL default '0',
|
`MinY` smallint(5) unsigned NOT NULL default '0',
|
||||||
`MaxY` smallint(5) unsigned NOT NULL default '0',
|
`MaxY` smallint(5) unsigned NOT NULL default '0',
|
||||||
`Score` smallint(5) unsigned NOT NULL default '0',
|
`Score` smallint(5) unsigned NOT NULL default '0',
|
||||||
|
PRIMARY KEY (`Id`),
|
||||||
KEY `EventId` (`EventId`),
|
KEY `EventId` (`EventId`),
|
||||||
KEY `MonitorId` (`MonitorId`),
|
KEY `MonitorId` (`MonitorId`),
|
||||||
KEY `ZoneId` (`ZoneId`)
|
KEY `ZoneId` (`ZoneId`)
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
--
|
||||||
|
-- Add primary keys for Logs and Stats tables
|
||||||
|
--
|
||||||
|
|
||||||
|
SET @s = (SELECT IF(
|
||||||
|
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
|
||||||
|
AND table_name = 'Logs'
|
||||||
|
AND column_name = 'Id'
|
||||||
|
) > 0,
|
||||||
|
"SELECT 'Column Id already exists in Logs'",
|
||||||
|
"ALTER TABLE `Logs` ADD COLUMN `Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`Id`)"
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE stmt FROM @s;
|
||||||
|
EXECUTE stmt;
|
||||||
|
|
||||||
|
SET @s = (SELECT IF(
|
||||||
|
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
|
||||||
|
AND table_name = 'Stats'
|
||||||
|
AND column_name = 'Id'
|
||||||
|
) > 0,
|
||||||
|
"SELECT 'Column Id already exists in Stats'",
|
||||||
|
"ALTER TABLE `Stats` ADD COLUMN `Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`Id`)"
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE stmt FROM @s;
|
||||||
|
EXECUTE stmt;
|
Loading…
Reference in New Issue