Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB IDO: Fix upgrade script for 2.11.0 (drop index only if existing) #7396

Merged
merged 2 commits into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/16-upgrading-icinga-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ It will also attempt to fix them, the following log entry is perfectly fine.

If you still encounter problems, please follow [this troubleshooting entry](15-troubleshooting.md#troubleshooting-api-missing-runtime-objects).

### DB IDO MySQL Schema <a id="upgrading-to-2-11-db-ido"></a>

The schema for MySQL contains an optional update which
drops unneeded indexes. You don't necessarily need to apply
this update.

### Documentation <a id="upgrading-to-2-11-documentation"></a>

* `Custom attributes` have been renamed to `Custom variables` following the name `vars` and their usage in backends and web interfaces.
Expand Down
103 changes: 76 additions & 27 deletions lib/db_ido_mysql/schema/upgrade/2.11.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,86 @@
-- upgrade path for Icinga 2.11.0
--
-- -----------------------------------------
-- Copyright (c) 2018 Icinga Development Team (https://icinga.com/)
-- Copyright (c) 2019 Icinga Development Team (https://icinga.com/)
--
-- Please check https://docs.icinga.com for upgrading information!
-- -----------------------------------------

ALTER TABLE `icinga_commands` DROP INDEX `commands_i_id_idx`;
ALTER TABLE `icinga_comments` DROP INDEX `idx_comments_object_id`;
ALTER TABLE `icinga_comments` DROP INDEX `comments_i_id_idx`;
ALTER TABLE `icinga_configfiles` DROP INDEX `configfiles_i_id_idx`;
ALTER TABLE `icinga_contactgroups` DROP INDEX `contactgroups_i_id_idx`;
ALTER TABLE `icinga_contacts` DROP INDEX `contacts_i_id_idx`;
ALTER TABLE `icinga_customvariables` DROP INDEX `idx_customvariables_object_id`;
ALTER TABLE `icinga_eventhandlers` DROP INDEX `eventhandlers_i_id_idx`;
ALTER TABLE `icinga_hostdependencies` DROP INDEX `hostdependencies_i_id_idx`;
ALTER TABLE `icinga_hostescalations` DROP INDEX `hostesc_i_id_idx`;
ALTER TABLE `icinga_hostescalation_contacts` DROP INDEX `hostesc_contacts_i_id_idx`;
ALTER TABLE `icinga_hostgroups` DROP INDEX `hostgroups_i_id_idx`;
ALTER TABLE `icinga_hosts` DROP INDEX `host_object_id`;
ALTER TABLE `icinga_hosts` DROP INDEX `hosts_i_id_idx`;
ALTER TABLE `icinga_objects` DROP INDEX `objects_objtype_id_idx`;
ALTER TABLE `icinga_programstatus` DROP INDEX `programstatus_i_id_idx`;
ALTER TABLE `icinga_runtimevariables` DROP INDEX `runtimevariables_i_id_idx`;
ALTER TABLE `icinga_scheduleddowntime` DROP INDEX `scheduleddowntime_i_id_idx`;
ALTER TABLE `icinga_scheduleddowntime` DROP INDEX `idx_scheduleddowntime_object_id`;
ALTER TABLE `icinga_serviceescalations` DROP INDEX `serviceesc_i_id_idx`;
ALTER TABLE `icinga_serviceescalation_contacts` DROP INDEX `serviceesc_contacts_i_id_idx`;
ALTER TABLE `icinga_servicegroups` DROP INDEX `servicegroups_i_id_idx`;
ALTER TABLE `icinga_services` DROP INDEX `services_i_id_idx`;
ALTER TABLE `icinga_services` DROP INDEX `service_object_id`;
ALTER TABLE `icinga_systemcommands` DROP INDEX `systemcommands_i_id_idx`;
ALTER TABLE `icinga_timeperiods` DROP INDEX `timeperiods_i_id_idx`;
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

-- --------------------------------------------------------
-- Helper functions and procedures for DROP INDEX IF EXISTS
-- --------------------------------------------------------

DELIMITER //
DROP FUNCTION IF EXISTS ido_index_exists //
CREATE FUNCTION ido_index_exists(
f_table_name varchar(64),
f_index_name varchar(64)
)
RETURNS BOOL
DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE index_exists BOOL DEFAULT FALSE;
SELECT EXISTS (
SELECT 1
FROM information_schema.statistics
WHERE table_schema = SCHEMA()
AND table_name = f_table_name
AND index_name = f_index_name
) INTO index_exists;
RETURN index_exists;
END //

DROP PROCEDURE IF EXISTS ido_drop_index_if_exists //
CREATE PROCEDURE ido_drop_index_if_exists (
IN p_table_name varchar(64),
IN p_index_name varchar(64)
)
DETERMINISTIC
MODIFIES SQL DATA
BEGIN
IF ido_index_exists(p_table_name, p_index_name)
THEN
SET @ido_drop_index_sql = CONCAT('ALTER TABLE `', SCHEMA(), '`.`', p_table_name, '` DROP INDEX `', p_index_name, '`');
PREPARE stmt FROM @ido_drop_index_sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @ido_drop_index_sql = NULL;
END IF;
END //
DELIMITER ;

CALL ido_drop_index_if_exists('icinga_commands', 'commands_i_id_idx');
CALL ido_drop_index_if_exists('icinga_comments', 'idx_comments_object_id');
CALL ido_drop_index_if_exists('icinga_comments', 'comments_i_id_idx');
CALL ido_drop_index_if_exists('icinga_configfiles', 'configfiles_i_id_idx');
CALL ido_drop_index_if_exists('icinga_contactgroups', 'contactgroups_i_id_idx');
CALL ido_drop_index_if_exists('icinga_contacts', 'contacts_i_id_idx');
CALL ido_drop_index_if_exists('icinga_customvariables', 'idx_customvariables_object_id');
CALL ido_drop_index_if_exists('icinga_eventhandlers', 'eventhandlers_i_id_idx');
CALL ido_drop_index_if_exists('icinga_hostdependencies', 'hostdependencies_i_id_idx');
CALL ido_drop_index_if_exists('icinga_hostescalations', 'hostesc_i_id_idx');
CALL ido_drop_index_if_exists('icinga_hostescalation_contacts', 'hostesc_contacts_i_id_idx');
CALL ido_drop_index_if_exists('icinga_hostgroups', 'hostgroups_i_id_idx');
CALL ido_drop_index_if_exists('icinga_hosts', 'host_object_id');
CALL ido_drop_index_if_exists('icinga_hosts', 'hosts_i_id_idx');
CALL ido_drop_index_if_exists('icinga_objects', 'objects_objtype_id_idx');
CALL ido_drop_index_if_exists('icinga_programstatus', 'programstatus_i_id_idx');
CALL ido_drop_index_if_exists('icinga_runtimevariables', 'runtimevariables_i_id_idx');
CALL ido_drop_index_if_exists('icinga_scheduleddowntime', 'scheduleddowntime_i_id_idx');
CALL ido_drop_index_if_exists('icinga_scheduleddowntime', 'idx_scheduleddowntime_object_id');
CALL ido_drop_index_if_exists('icinga_serviceescalations', 'serviceesc_i_id_idx');
CALL ido_drop_index_if_exists('icinga_serviceescalation_contacts', 'serviceesc_contacts_i_id_idx');
CALL ido_drop_index_if_exists('icinga_servicegroups', 'servicegroups_i_id_idx');
CALL ido_drop_index_if_exists('icinga_services', 'services_i_id_idx');
CALL ido_drop_index_if_exists('icinga_services', 'service_object_id');
CALL ido_drop_index_if_exists('icinga_systemcommands', 'systemcommands_i_id_idx');
CALL ido_drop_index_if_exists('icinga_timeperiods', 'timeperiods_i_id_idx');

DROP FUNCTION ido_index_exists;
DROP PROCEDURE ido_drop_index_if_exists;

-- -----------------------------------------
-- set dbversion (same as 2.11.0)
Expand Down