check if already exist before apply (#1254)

This commit is contained in:
bash
2025-05-01 01:14:51 +02:00
committed by GitHub
parent 20e8ad21d5
commit 0e8a19b2fa

View File

@@ -5,5 +5,21 @@
-- # Date: 2025-04-26
-- ##########################################################
ALTER TABLE `playerbots_random_bots`
ADD INDEX `idx_owner_bot_event` (`owner`, `bot`, `event`);
-- Check if the index already exists
SET @index_exists := (
SELECT COUNT(1)
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'playerbots_random_bots'
AND INDEX_NAME = 'idx_owner_bot_event'
);
-- Conditionally create the index only if it doesn't exist
SET @ddl := IF(@index_exists = 0,
'ALTER TABLE `playerbots_random_bots` ADD INDEX `idx_owner_bot_event` (`owner`, `bot`, `event`);',
'SELECT "Index idx_owner_bot_event already exists.";'
);
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;