From e4525a09df0fd3749259fd1812c780e8a4417263 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 15 Dec 2016 16:21:49 +0100 Subject: [PATCH] upgrade_126: re-order queries ...otherwise we might delete indexes before the related constraint in case they are different refs #13591 --- schema/mysql-migrations/upgrade_126.sql | 142 ++++++++++++------------ 1 file changed, 73 insertions(+), 69 deletions(-) diff --git a/schema/mysql-migrations/upgrade_126.sql b/schema/mysql-migrations/upgrade_126.sql index 3df3144c..ef14078b 100644 --- a/schema/mysql-migrations/upgrade_126.sql +++ b/schema/mysql-migrations/upgrade_126.sql @@ -15,23 +15,6 @@ EXECUTE stmt; DEALLOCATE PREPARE stmt; SET @stmt = NULL; -SET @stmt = (SELECT IF( - (SELECT EXISTS( - SELECT 1 - FROM information_schema.statistics - WHERE table_schema = SCHEMA() - AND table_name = 'icinga_service_set' - AND index_name = 'icinga_service_set_host' - )), - 'ALTER TABLE icinga_service_set DROP INDEX icinga_service_set_host', - 'SELECT 1' -)); - -PREPARE stmt FROM @stmt; -EXECUTE stmt; -DEALLOCATE PREPARE stmt; -SET @stmt = NULL; - SET @stmt = (SELECT IF( (SELECT EXISTS( @@ -50,23 +33,6 @@ EXECUTE stmt; DEALLOCATE PREPARE stmt; SET @stmt = NULL; -SET @stmt = (SELECT IF( - (SELECT EXISTS( - SELECT 1 - FROM information_schema.statistics - WHERE table_schema = SCHEMA() - AND table_name = 'icinga_service_set' - AND index_name = 'icinga_service_set_ibfk_1' - )), - 'ALTER TABLE icinga_service_set DROP INDEX icinga_service_set_ibfk_1', - 'SELECT 1' -)); - -PREPARE stmt FROM @stmt; -EXECUTE stmt; -DEALLOCATE PREPARE stmt; -SET @stmt = NULL; - SET @stmt = (SELECT IF( (SELECT EXISTS( @@ -85,24 +51,6 @@ EXECUTE stmt; DEALLOCATE PREPARE stmt; SET @stmt = NULL; -SET @stmt = (SELECT IF( - (SELECT EXISTS( - SELECT 1 - FROM information_schema.statistics - WHERE table_schema = SCHEMA() - AND table_name = 'icinga_service_set' - AND index_name = 'icinga_service_set_ibfk_2' - )), - 'ALTER TABLE icinga_service_set DROP INDEX icinga_service_set_ibfk_2', - 'SELECT 1' -)); - -PREPARE stmt FROM @stmt; -EXECUTE stmt; -DEALLOCATE PREPARE stmt; -SET @stmt = NULL; - - SET @stmt = (SELECT IF( (SELECT EXISTS( @@ -121,23 +69,6 @@ EXECUTE stmt; DEALLOCATE PREPARE stmt; SET @stmt = NULL; -SET @stmt = (SELECT IF( - (SELECT EXISTS( - SELECT 1 - FROM information_schema.statistics - WHERE table_schema = SCHEMA() - AND table_name = 'icinga_service' - AND index_name = 'icinga_service_service_set' - )), - 'ALTER TABLE icinga_service DROP INDEX icinga_service_service_set', - 'SELECT 1' -)); - -PREPARE stmt FROM @stmt; -EXECUTE stmt; -DEALLOCATE PREPARE stmt; -SET @stmt = NULL; - SET @stmt = (SELECT IF( (SELECT EXISTS( @@ -156,6 +87,61 @@ EXECUTE stmt; DEALLOCATE PREPARE stmt; SET @stmt = NULL; + +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT 1 + FROM information_schema.statistics + WHERE table_schema = SCHEMA() + AND table_name = 'icinga_service' + AND index_name = 'icinga_service_service_set' + )), + 'ALTER TABLE icinga_service DROP INDEX icinga_service_service_set', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT 1 + FROM information_schema.statistics + WHERE table_schema = SCHEMA() + AND table_name = 'icinga_service_set' + AND index_name = 'icinga_service_set_ibfk_1' + )), + 'ALTER TABLE icinga_service_set DROP INDEX icinga_service_set_ibfk_1', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT 1 + FROM information_schema.statistics + WHERE table_schema = SCHEMA() + AND table_name = 'icinga_service_set' + AND index_name = 'icinga_service_set_host' + )), + 'ALTER TABLE icinga_service_set DROP INDEX icinga_service_set_host', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + SET @stmt = (SELECT IF( (SELECT EXISTS( SELECT 1 @@ -174,6 +160,24 @@ DEALLOCATE PREPARE stmt; SET @stmt = NULL; +SET @stmt = (SELECT IF( + (SELECT EXISTS( + SELECT 1 + FROM information_schema.statistics + WHERE table_schema = SCHEMA() + AND table_name = 'icinga_service_set' + AND index_name = 'icinga_service_set_ibfk_2' + )), + 'ALTER TABLE icinga_service_set DROP INDEX icinga_service_set_ibfk_2', + 'SELECT 1' +)); + +PREPARE stmt FROM @stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +SET @stmt = NULL; + + ALTER TABLE icinga_service_set ADD CONSTRAINT icinga_service_set_host FOREIGN KEY host (host_id)