From dd75a5edbcb24ef39093c06d88928c6d145c9403 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 18 Mar 2024 10:22:35 +0100 Subject: [PATCH 1/2] `schema/mysql`: Use `UNIX_TIMESTAMP()` instead of `CURRENT_TIMESTMAP()` `CURRENT_TIMESTAMP()` an alias for `NOW()` returns the current date and time in the format `YYYY-MM-DD hh:mm:ss` using the session time zone. Since we are using numeric context, the value is stored in the format `YYYYMMDDhhmmss`. But actually we want to set a (millisecond) UNIX timestamp here, so we need to use `UNIX_TIMESTAMP()` instead. --- schema/mysql/schema.sql | 2 +- schema/mysql/upgrades/1.0.0-rc2.sql | 2 +- schema/mysql/upgrades/1.0.0.sql | 2 +- schema/mysql/upgrades/1.1.1.sql | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/schema/mysql/schema.sql b/schema/mysql/schema.sql index f4434f139..26ae3940d 100644 --- a/schema/mysql/schema.sql +++ b/schema/mysql/schema.sql @@ -1343,4 +1343,4 @@ CREATE TABLE icingadb_schema ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC; INSERT INTO icingadb_schema (version, timestamp) - VALUES (4, CURRENT_TIMESTAMP() * 1000); + VALUES (4, UNIX_TIMESTAMP() * 1000); diff --git a/schema/mysql/upgrades/1.0.0-rc2.sql b/schema/mysql/upgrades/1.0.0-rc2.sql index 50fb2f98d..d4695cd81 100644 --- a/schema/mysql/upgrades/1.0.0-rc2.sql +++ b/schema/mysql/upgrades/1.0.0-rc2.sql @@ -156,7 +156,7 @@ ALTER TABLE acknowledgement_history MODIFY is_persistent enum('n','y') DEFAULT NULL COMMENT 'NULL if ack_set event happened before Icinga DB history recording'; INSERT INTO icingadb_schema (version, timestamp) - VALUES (2, CURRENT_TIMESTAMP() * 1000); + VALUES (2, UNIX_TIMESTAMP() * 1000); ALTER TABLE host_state MODIFY output longtext DEFAULT NULL, diff --git a/schema/mysql/upgrades/1.0.0.sql b/schema/mysql/upgrades/1.0.0.sql index 16bb45e3b..054e10e4e 100644 --- a/schema/mysql/upgrades/1.0.0.sql +++ b/schema/mysql/upgrades/1.0.0.sql @@ -288,4 +288,4 @@ INSERT INTO sla_history_downtime ON DUPLICATE KEY UPDATE sla_history_downtime.downtime_id = sla_history_downtime.downtime_id; INSERT INTO icingadb_schema (version, TIMESTAMP) - VALUES (3, CURRENT_TIMESTAMP() * 1000); + VALUES (3, UNIX_TIMESTAMP() * 1000); diff --git a/schema/mysql/upgrades/1.1.1.sql b/schema/mysql/upgrades/1.1.1.sql index 264ecae3e..b0d5b698d 100644 --- a/schema/mysql/upgrades/1.1.1.sql +++ b/schema/mysql/upgrades/1.1.1.sql @@ -34,4 +34,4 @@ ALTER TABLE history UNLOCK TABLES; INSERT INTO icingadb_schema (version, timestamp) - VALUES (4, CURRENT_TIMESTAMP() * 1000); + VALUES (4, UNIX_TIMESTAMP() * 1000); From 9b213d528bfc69f8f3433438e2dbbe367984c894 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 18 Mar 2024 10:29:31 +0100 Subject: [PATCH 2/2] `schmema/mysql/1.1.2`: Fix timestamp is not UNIX time We previously incorrectly used `CURRENT_TIMESTAMP()` instead of `UNIX_TIMESTAMP()` so the timestamps need to be corrected. --- schema/mysql/upgrades/1.1.2.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 schema/mysql/upgrades/1.1.2.sql diff --git a/schema/mysql/upgrades/1.1.2.sql b/schema/mysql/upgrades/1.1.2.sql new file mode 100644 index 000000000..9f5edd5fa --- /dev/null +++ b/schema/mysql/upgrades/1.1.2.sql @@ -0,0 +1 @@ +UPDATE icingadb_schema SET timestamp = UNIX_TIMESTAMP(timestamp / 1000) * 1000 WHERE timestamp > 20000000000000000;