Debian Codegraph @

lib/db_ido_mysql/schema/upgrade/2.11.0.sql

raw
1 -- -----------------------------------------
2 -- upgrade path for Icinga 2.11.0
3 --
4 -- -----------------------------------------
5 -- SPDX-FileCopyrightText: 2019 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_commands', 'commands_i_id_idx');
58 CALL ido_drop_index_if_exists('icinga_comments', 'idx_comments_object_id');
59 CALL ido_drop_index_if_exists('icinga_comments', 'comments_i_id_idx');
60 CALL ido_drop_index_if_exists('icinga_configfiles', 'configfiles_i_id_idx');
61 CALL ido_drop_index_if_exists('icinga_contactgroups', 'contactgroups_i_id_idx');
62 CALL ido_drop_index_if_exists('icinga_contacts', 'contacts_i_id_idx');
63 CALL ido_drop_index_if_exists('icinga_customvariables', 'idx_customvariables_object_id');
64 CALL ido_drop_index_if_exists('icinga_eventhandlers', 'eventhandlers_i_id_idx');
65 CALL ido_drop_index_if_exists('icinga_hostdependencies', 'hostdependencies_i_id_idx');
66 CALL ido_drop_index_if_exists('icinga_hostescalations', 'hostesc_i_id_idx');
67 CALL ido_drop_index_if_exists('icinga_hostescalation_contacts', 'hostesc_contacts_i_id_idx');
68 CALL ido_drop_index_if_exists('icinga_hostgroups', 'hostgroups_i_id_idx');
69 CALL ido_drop_index_if_exists('icinga_hosts', 'host_object_id');
70 CALL ido_drop_index_if_exists('icinga_hosts', 'hosts_i_id_idx');
71 CALL ido_drop_index_if_exists('icinga_objects', 'objects_objtype_id_idx');
72 CALL ido_drop_index_if_exists('icinga_programstatus', 'programstatus_i_id_idx');
73 CALL ido_drop_index_if_exists('icinga_runtimevariables', 'runtimevariables_i_id_idx');
74 CALL ido_drop_index_if_exists('icinga_scheduleddowntime', 'scheduleddowntime_i_id_idx');
75 CALL ido_drop_index_if_exists('icinga_scheduleddowntime', 'idx_scheduleddowntime_object_id');
76 CALL ido_drop_index_if_exists('icinga_serviceescalations', 'serviceesc_i_id_idx');
77 CALL ido_drop_index_if_exists('icinga_serviceescalation_contacts', 'serviceesc_contacts_i_id_idx');
78 CALL ido_drop_index_if_exists('icinga_servicegroups', 'servicegroups_i_id_idx');
79 CALL ido_drop_index_if_exists('icinga_services', 'services_i_id_idx');
80 CALL ido_drop_index_if_exists('icinga_services', 'service_object_id');
81 CALL ido_drop_index_if_exists('icinga_systemcommands', 'systemcommands_i_id_idx');
82 CALL ido_drop_index_if_exists('icinga_timeperiods', 'timeperiods_i_id_idx');
83
84 DROP FUNCTION ido_index_exists;
85 DROP PROCEDURE ido_drop_index_if_exists;
86
87 -- -----------------------------------------
88 -- set dbversion (same as 2.11.0)
89 -- -----------------------------------------
90 INSERT INTO icinga_dbversion (name, version, create_time, modify_time) VALUES ('idoutils', '1.15.0', NOW(), NOW()) ON DUPLICATE KEY UPDATE version='1.15.0', modify_time=NOW();