ALTER Events.Id to BIGINT. This update got lost at somepoint. Add FOREIGN KEYS to Frames, Stats and Zones tables

This commit is contained in:
Isaac Connor 2020-10-28 12:38:44 -04:00
parent 59884375fa
commit 43b7021f9c
1 changed files with 22 additions and 0 deletions

22
db/zm_update-1.35.11.sql Normal file
View File

@ -0,0 +1,22 @@
/* Change Id type to BIGINT. */
ALTER TABLE Events MODIFY Id bigint unsigned NOT NULL auto_increment;
/* Add FOREIGN KEYS After deleting lost records */
DELETE FROM Frames WHERE EventId NOT IN (SELECT Id FROM Events);
ALTER TABLE Frames ADD FOREIGN KEY (EventId) REFERENCES Events (Id) ON DELETE CASCADE;
/* Add FOREIGN KEYS After deleting lost records */
DELETE FROM Stats WHERE EventId NOT IN (SELECT Id FROM Events);
ALTER TABLE Stats ADD FOREIGN KEY (EventId) REFERENCES Events (Id) ON DELETE CASCADE;
DELETE FROM Stats WHERE MonitorId NOT IN (SELECT Id FROM Monitors);
ALTER TABLE Stats ADD FOREIGN KEY (`MonitorId`) REFERENCES `Monitors` (`Id`) ON DELETE CASCADE;
DELETE FROM Stats WHERE ZoneId NOT IN (SELECT Id FROM Zones);
ALTER TABLE Stats ADD FOREIGN KEY (`ZoneId`) REFERENCES `Zones` (`Id`) ON DELETE CASCADE;
/* Add FOREIGN KEYS After deleting lost records */
DELETE FROM Zones WHERE MonitorId NOT IN (SELECT Id FROM Monitors);
ALTER TABLE Zones ADD FOREIGN KEY (`MonitorId`) REFERENCES `Monitors` (`Id`) ON DELETE CASCADE;