diff --git a/schema/mysql/schema.sql b/schema/mysql/schema.sql index a5ea24ba..7ffb34f6 100644 --- a/schema/mysql/schema.sql +++ b/schema/mysql/schema.sql @@ -608,13 +608,13 @@ CREATE TABLE downtime ( scheduled_start_time bigint unsigned NOT NULL, scheduled_end_time bigint unsigned NOT NULL, scheduled_duration bigint unsigned NOT NULL, - flexible_duration bigint unsigned NOT NULL, is_flexible enum('n', 'y') NOT NULL, + flexible_duration bigint unsigned NOT NULL, is_in_effect enum('n', 'y') NOT NULL, start_time bigint unsigned DEFAULT NULL COMMENT 'Time when the host went into a problem state during the downtimes timeframe', end_time bigint unsigned DEFAULT NULL COMMENT 'Problem state assumed: scheduled_end_time if fixed, start_time + flexible_duration otherwise', - duration bigint unsigned NOT NULL COMMENT 'Duration of the downtime: When the downtime is flexible, this is the same as flexible_duration otherwise scheduled_end_time - scheduled_start_time', + duration bigint unsigned NOT NULL COMMENT 'Duration of the downtime: When the downtime is flexible, this is the same as flexible_duration otherwise scheduled_duration', scheduled_by varchar(767) DEFAULT NULL COMMENT 'Name of the ScheduledDowntime which created this Downtime. 255+1+255+1+255, i.e. "host.name!service.name!scheduled-downtime-name"', zone_id binary(20) DEFAULT NULL COMMENT 'zone.id', diff --git a/schema/mysql/upgrades/1.0.0-rc2.sql b/schema/mysql/upgrades/1.0.0-rc2.sql index 2450ac56..a2432f1f 100644 --- a/schema/mysql/upgrades/1.0.0-rc2.sql +++ b/schema/mysql/upgrades/1.0.0-rc2.sql @@ -15,12 +15,9 @@ ALTER TABLE service_state ADD COLUMN properties_checksum binary(20) AFTER enviro UPDATE service_state SET properties_checksum = 0; ALTER TABLE service_state MODIFY COLUMN properties_checksum binary(20) COMMENT 'sha1(all properties)' NOT NULL; ALTER TABLE service_state ADD UNIQUE INDEX idx_service_state_service_id (service_id); -ALTER TABLE service_state ADD COLUMN host_id binary(20) NOT NULL COMMENT 'host.id' AFTER id; ALTER TABLE downtime ADD COLUMN parent_id binary(20) COMMENT 'For service downtimes, the ID of the host downtime that created this downtime by using the "all_services" flag of the schedule-downtime API.' AFTER triggered_by_id, - ADD COLUMN scheduled_duration bigint unsigned NOT NULL AFTER scheduled_end_time, - ADD COLUMN duration bigint unsigned NOT NULL COMMENT 'Duration of the downtime: When the downtime is flexible, this is the same as flexible_duration otherwise scheduled_end_time - scheduled_start_time' AFTER end_time, MODIFY COLUMN triggered_by_id binary(20) COMMENT 'The ID of the downtime that triggered this downtime. This is set when creating downtimes on a host or service higher up in the dependency chain using the "child_option" "DowntimeTriggeredChildren" and can also be set manually via the API.'; ALTER TABLE downtime_history ADD COLUMN parent_id binary(20) COMMENT 'For service downtimes, the ID of the host downtime that created this downtime by using the "all_services" flag of the schedule-downtime API.' AFTER triggered_by_id, @@ -412,3 +409,12 @@ ALTER TABLE eventcommand_customvar ALTER TABLE notificationcommand_customvar ADD INDEX idx_notificationcommand_customvar_notificationcommand_id (notificationcommand_id, customvar_id), ADD INDEX idx_notificationcommand_customvar_customvar_id (customvar_id, notificationcommand_id); + +ALTER TABLE downtime + ADD COLUMN scheduled_duration bigint unsigned NOT NULL AFTER scheduled_end_time, + ADD COLUMN duration bigint unsigned NOT NULL COMMENT 'Duration of the downtime: When the downtime is flexible, this is the same as flexible_duration otherwise scheduled_duration' AFTER end_time, + MODIFY COLUMN flexible_duration bigint unsigned NOT NULL AFTER is_flexible; +UPDATE downtime SET scheduled_duration = scheduled_end_time - scheduled_start_time, duration = (CASE WHEN is_flexible = 'y' THEN flexible_duration ELSE scheduled_end_time - scheduled_start_time END) WHERE scheduled_duration = 0; + +ALTER TABLE service_state ADD COLUMN host_id binary(20) NOT NULL COMMENT 'host.id' AFTER id; +UPDATE service_state INNER JOIN service ON service.id = service_state.service_id SET service_state.host_id = service.host_id WHERE service_state.host_id = REPEAT('\0', 20);