2021-10-17 08:37:16 +08:00
|
|
|
SET @s = (SELECT IF(
|
|
|
|
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
|
|
|
|
AND table_name = 'Monitors'
|
2021-11-11 08:20:39 +08:00
|
|
|
AND column_name = 'ManufacturerId'
|
2021-10-17 08:37:16 +08:00
|
|
|
) > 0,
|
2021-11-11 08:20:39 +08:00
|
|
|
"SELECT 'Column ManufacturerId already exists in Monitors'",
|
|
|
|
"ALTER TABLE `Monitors` ADD `ManufacturerId` int(10) unsigned AFTER `StorageId`"
|
2021-10-17 08:37:16 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
PREPARE stmt FROM @s;
|
|
|
|
EXECUTE stmt;
|
|
|
|
|
|
|
|
SET @s = (SELECT IF(
|
2021-11-11 08:20:39 +08:00
|
|
|
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE table_schema = DATABASE()
|
2021-10-17 08:37:16 +08:00
|
|
|
AND table_name = 'Monitors'
|
2021-11-11 08:20:39 +08:00
|
|
|
AND column_name = 'ManufacturerId'
|
2021-10-17 08:37:16 +08:00
|
|
|
) > 0,
|
2021-11-11 08:20:39 +08:00
|
|
|
"SELECT 'FOREIGN KEY for ManufacturerId already exists in Monitors'",
|
|
|
|
"ALTER TABLE `Monitors` ADD FOREIGN KEY (`ManufacturerId`) REFERENCES `Manufacturers` (Id)"
|
2021-10-17 08:37:16 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
PREPARE stmt FROM @s;
|
|
|
|
EXECUTE stmt;
|
|
|
|
|
2021-11-11 08:20:39 +08:00
|
|
|
SET @s = (SELECT IF(
|
2021-10-17 08:37:16 +08:00
|
|
|
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
|
|
|
|
AND table_name = 'Monitors'
|
2021-11-11 08:20:39 +08:00
|
|
|
AND column_name = 'ModelId'
|
2021-10-17 08:37:16 +08:00
|
|
|
) > 0,
|
2021-11-11 08:20:39 +08:00
|
|
|
"SELECT 'Column ModelId already exists in Monitors'",
|
|
|
|
"ALTER TABLE `Monitors` ADD `ModelId` int(10) unsigned AFTER `ManufacturerId`"
|
2021-10-17 08:37:16 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
PREPARE stmt FROM @s;
|
|
|
|
EXECUTE stmt;
|
|
|
|
|
|
|
|
SET @s = (SELECT IF(
|
2021-11-11 08:20:39 +08:00
|
|
|
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE table_schema = DATABASE()
|
2021-10-17 08:37:16 +08:00
|
|
|
AND table_name = 'Monitors'
|
2021-11-11 08:20:39 +08:00
|
|
|
AND column_name = 'ModelId'
|
2021-10-17 08:37:16 +08:00
|
|
|
) > 0,
|
2021-11-11 08:20:39 +08:00
|
|
|
"SELECT 'FOREIGN KEY for ModelId already exists in Monitors'",
|
|
|
|
"ALTER TABLE `Monitors` ADD FOREIGN KEY (`ModelId`) REFERENCES `Models` (Id)"
|
2021-10-17 08:37:16 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
PREPARE stmt FROM @s;
|
|
|
|
EXECUTE stmt;
|
|
|
|
|
2021-11-15 22:47:11 +08:00
|
|
|
SET @s = (SELECT IF(
|
2021-10-17 08:37:16 +08:00
|
|
|
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
|
2021-11-15 22:47:11 +08:00
|
|
|
AND table_name = 'MonitorPresets'
|
|
|
|
AND column_name = 'ModelId'
|
|
|
|
) > 0,
|
|
|
|
"SELECT 'Column ModelId already exists in MonitorPresets'",
|
|
|
|
"ALTER TABLE `MonitorPresets` ADD `ModelId` int(10) unsigned AFTER `Id`"
|
|
|
|
));
|
|
|
|
|
|
|
|
PREPARE stmt FROM @s;
|
|
|
|
EXECUTE stmt;
|
2022-01-01 06:53:36 +08:00
|
|
|
|
2021-11-15 22:47:11 +08:00
|
|
|
SET @s = (SELECT IF(
|
|
|
|
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE table_schema = DATABASE()
|
|
|
|
AND table_name = 'MonitorPresets'
|
|
|
|
AND column_name = 'ModelId'
|
2021-10-17 08:37:16 +08:00
|
|
|
) > 0,
|
2021-11-15 22:47:11 +08:00
|
|
|
"SELECT 'FOREIGN KEY for ModelId already exists in MonitorPresets'",
|
|
|
|
"ALTER TABLE `MonitorPresets` ADD FOREIGN KEY (`ModelId`) REFERENCES `Models` (Id)"
|
2021-10-17 08:37:16 +08:00
|
|
|
));
|
|
|
|
|
|
|
|
PREPARE stmt FROM @s;
|
|
|
|
EXECUTE stmt;
|
2021-11-16 05:30:39 +08:00
|
|
|
|
|
|
|
UPDATE `MonitorPresets` SET `ModelId`=(SELECT `Id` FROM `Models` WHERE `Name`='IP8M-T2499EW') WHERE `Name` like 'Amcrest, IP8M-T2499EW
|
|
|
|
%';
|