| 1 |
-- ----------------------------------------- |
| 2 |
-- upgrade path for Icinga 2.8.1 (fix for fresh 2.8.0 installation only) |
| 3 |
-- |
| 4 |
-- ----------------------------------------- |
| 5 |
-- SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com> |
| 6 |
-- SPDX-License-Identifier: GPL-2.0-or-later |
| 7 |
-- |
| 8 |
-- Please check https://docs.icinga.com for upgrading information! |
| 9 |
-- ----------------------------------------- |
| 10 |
|
| 11 |
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; |
| 12 |
|
| 13 |
-- -------------------------------------------------------- |
| 14 |
-- Helper functions and procedures for DROP INDEX IF EXISTS |
| 15 |
-- -------------------------------------------------------- |
| 16 |
|
| 17 |
DELIMITER // |
| 18 |
DROP FUNCTION IF EXISTS ido_index_exists // |
| 19 |
CREATE FUNCTION ido_index_exists( |
| 20 |
f_table_name varchar(64), |
| 21 |
f_index_name varchar(64) |
| 22 |
) |
| 23 |
RETURNS BOOL |
| 24 |
DETERMINISTIC |
| 25 |
READS SQL DATA |
| 26 |
BEGIN |
| 27 |
DECLARE index_exists BOOL DEFAULT FALSE; |
| 28 |
SELECT EXISTS ( |
| 29 |
SELECT 1 |
| 30 |
FROM information_schema.statistics |
| 31 |
WHERE table_schema = SCHEMA() |
| 32 |
AND table_name = f_table_name |
| 33 |
AND index_name = f_index_name |
| 34 |
) INTO index_exists; |
| 35 |
RETURN index_exists; |
| 36 |
END // |
| 37 |
|
| 38 |
DROP PROCEDURE IF EXISTS ido_drop_index_if_exists // |
| 39 |
CREATE PROCEDURE ido_drop_index_if_exists ( |
| 40 |
IN p_table_name varchar(64), |
| 41 |
IN p_index_name varchar(64) |
| 42 |
) |
| 43 |
DETERMINISTIC |
| 44 |
MODIFIES SQL DATA |
| 45 |
BEGIN |
| 46 |
IF ido_index_exists(p_table_name, p_index_name) |
| 47 |
THEN |
| 48 |
SET @ido_drop_index_sql = CONCAT('ALTER TABLE `', SCHEMA(), '`.`', p_table_name, '` DROP INDEX `', p_index_name, '`'); |
| 49 |
PREPARE stmt FROM @ido_drop_index_sql; |
| 50 |
EXECUTE stmt; |
| 51 |
DEALLOCATE PREPARE stmt; |
| 52 |
SET @ido_drop_index_sql = NULL; |
| 53 |
END IF; |
| 54 |
END // |
| 55 |
DELIMITER ; |
| 56 |
|
| 57 |
CALL ido_drop_index_if_exists('icinga_downtimehistory', 'instance_id'); |
| 58 |
CALL ido_drop_index_if_exists('icinga_scheduleddowntime', 'instance_id'); |
| 59 |
CALL ido_drop_index_if_exists('icinga_commenthistory', 'instance_id'); |
| 60 |
CALL ido_drop_index_if_exists('icinga_comments', 'instance_id'); |
| 61 |
|
| 62 |
DROP FUNCTION ido_index_exists; |
| 63 |
DROP PROCEDURE ido_drop_index_if_exists; |
| 64 |
|
| 65 |
-- ----------------------------------------- |
| 66 |
-- set dbversion (same as 2.8.0) |
| 67 |
-- ----------------------------------------- |
| 68 |
INSERT INTO icinga_dbversion (name, version, create_time, modify_time) VALUES ('idoutils', '1.14.3', NOW(), NOW()) ON DUPLICATE KEY UPDATE version='1.14.3', modify_time=NOW(); |