Skip to content

Commit

Permalink
Fail migrating schedule config when named timezones aren't loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Nov 15, 2023
1 parent 53ef685 commit 5895d8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions doc/80-Upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Icinga Web provides you the ability to perform such migrations in a simple way.
automation if you're an Icinga Director user. For those who are not using the latest version of Icinga Web, please
follow the instructions below.

> **Note**
>
> If you're not using Icinga Web migration automation, you may need to [populate](https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html#time-zone-installation)
> all the system named time zone information into your MSQL/MariaDB server. Otherwise, the migration may not succeed.
You may use the following command to apply the database schema upgrade file:
<!-- {% if not icingaDocs %} -->

Expand Down
11 changes: 10 additions & 1 deletion schema/mysql-upgrades/1.0.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ DROP PROCEDURE IF EXISTS migrate_schedule_config;
DELIMITER //
CREATE PROCEDURE migrate_schedule_config()
BEGIN
DECLARE session_time_zone text;

DECLARE schedule_id int;
DECLARE schedule_start bigint;
DECLARE schedule_frequency enum('minutely', 'hourly', 'daily', 'weekly', 'monthly');
Expand All @@ -13,6 +15,13 @@ BEGIN
DECLARE schedule CURSOR FOR SELECT id, start, frequency, config FROM schedule;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

-- Determine the current session time zone name
SELECT IF(@@session.TIME_ZONE = 'SYSTEM', @@system_time_zone, @@session.TIME_ZONE) INTO session_time_zone;

IF session_time_zone NOT LIKE '+%:%' AND session_time_zone NOT LIKE '-%:%' AND CONVERT_TZ(FROM_UNIXTIME(1699903042), session_time_zone, '+00:00') IS NULL THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'required named time zone information are not populated into mysql/mariadb';
END IF;

OPEN schedule;
read_loop: LOOP
FETCH schedule INTO schedule_id, schedule_start, schedule_frequency, schedule_config;
Expand All @@ -23,7 +32,7 @@ BEGIN
SET frequency_json = CONCAT(
',"frequencyType":"\\\\ipl\\\\Scheduler\\\\Cron","frequency":"{',
'\\"expression\\":\\"@', schedule_frequency,
'\\",\\"start\\":\\"', DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(schedule_start / 1000), @@session.TIME_ZONE, 'UTC'), '%Y-%m-%dT%H:%i:%s.%f UTC'),
'\\",\\"start\\":\\"', DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(schedule_start / 1000), session_time_zone, '+00:00'), '%Y-%m-%dT%H:%i:%s.%f UTC'),
'\\"}"'
);
UPDATE schedule SET config = INSERT(schedule_config, LENGTH(schedule_config), 0, frequency_json) WHERE id = schedule_id;
Expand Down

0 comments on commit 5895d8e

Please sign in to comment.