From 724ed4ebb2d81db6420c0ef330f304d2994b7b2f Mon Sep 17 00:00:00 2001 From: Johannes Rauh Date: Mon, 27 Oct 2025 12:50:08 +0100 Subject: [PATCH 1/3] Add timezone column to mysql schema --- schema/mysql/schema.sql | 1 + schema/mysql/upgrades/0.2.0-schedule-timezone.sql | 1 + 2 files changed, 2 insertions(+) create mode 100644 schema/mysql/upgrades/0.2.0-schedule-timezone.sql diff --git a/schema/mysql/schema.sql b/schema/mysql/schema.sql index e0ce1b37..5f6014dd 100644 --- a/schema/mysql/schema.sql +++ b/schema/mysql/schema.sql @@ -94,6 +94,7 @@ CREATE INDEX idx_contactgroup_member_changed_at ON contactgroup_member(changed_a CREATE TABLE schedule ( id bigint NOT NULL AUTO_INCREMENT, name text NOT NULL COLLATE utf8mb4_unicode_ci, + timezone text NOT NULL, -- e.g. 'Europe/Berlin' changed_at bigint NOT NULL, deleted enum('n', 'y') NOT NULL DEFAULT 'n', diff --git a/schema/mysql/upgrades/0.2.0-schedule-timezone.sql b/schema/mysql/upgrades/0.2.0-schedule-timezone.sql new file mode 100644 index 00000000..c7de6e26 --- /dev/null +++ b/schema/mysql/upgrades/0.2.0-schedule-timezone.sql @@ -0,0 +1 @@ +ALTER TABLE schedule ADD COLUMN timezone text NOT NULL AFTER name; From dd8fa78c39f4b966d384a4eadb96e8a800154cb7 Mon Sep 17 00:00:00 2001 From: Johannes Rauh Date: Mon, 27 Oct 2025 12:50:21 +0100 Subject: [PATCH 2/3] Add timezone column to pgsql schema --- schema/pgsql/schema.sql | 1 + schema/pgsql/upgrades/0.2.0-schedule-timezone.sql | 1 + 2 files changed, 2 insertions(+) create mode 100644 schema/pgsql/upgrades/0.2.0-schedule-timezone.sql diff --git a/schema/pgsql/schema.sql b/schema/pgsql/schema.sql index 35381d3a..bfe063f2 100644 --- a/schema/pgsql/schema.sql +++ b/schema/pgsql/schema.sql @@ -127,6 +127,7 @@ CREATE INDEX idx_contactgroup_member_changed_at ON contactgroup_member(changed_a CREATE TABLE schedule ( id bigserial, name citext NOT NULL, + timezone text NOT NULL, -- e.g. 'Europe/Berlin' changed_at bigint NOT NULL, deleted boolenum NOT NULL DEFAULT 'n', diff --git a/schema/pgsql/upgrades/0.2.0-schedule-timezone.sql b/schema/pgsql/upgrades/0.2.0-schedule-timezone.sql new file mode 100644 index 00000000..ed93d2e0 --- /dev/null +++ b/schema/pgsql/upgrades/0.2.0-schedule-timezone.sql @@ -0,0 +1 @@ +ALTER TABLE schedule ADD COLUMN timezone text NOT NULL; From 8cf406743599c082e9b01fb5fa27969c909f1de6 Mon Sep 17 00:00:00 2001 From: Johannes Rauh Date: Tue, 28 Oct 2025 08:24:57 +0100 Subject: [PATCH 3/3] Add default value for `schedule.timezone` upgrades The value must not be null, so we have to set a default when upgrading the schema. For that we look for the first `timeperiod_entry` and use it's `timezone` column. If no entry exists, the fallback is **'UTC'**. --- schema/mysql/upgrades/0.2.0-schedule-timezone.sql | 13 ++++++++++++- schema/pgsql/upgrades/0.2.0-schedule-timezone.sql | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/schema/mysql/upgrades/0.2.0-schedule-timezone.sql b/schema/mysql/upgrades/0.2.0-schedule-timezone.sql index c7de6e26..b1e6c3c1 100644 --- a/schema/mysql/upgrades/0.2.0-schedule-timezone.sql +++ b/schema/mysql/upgrades/0.2.0-schedule-timezone.sql @@ -1 +1,12 @@ -ALTER TABLE schedule ADD COLUMN timezone text NOT NULL AFTER name; +ALTER TABLE schedule ADD COLUMN timezone text AFTER name; +UPDATE schedule SET timezone = ( + SELECT entry.timezone + FROM timeperiod_entry entry + INNER JOIN timeperiod ON timeperiod.id = entry.timeperiod_id + INNER JOIN rotation ON rotation.id = timeperiod.owned_by_rotation_id + WHERE rotation.schedule_id = schedule.id + ORDER BY entry.id + LIMIT 1 +); +UPDATE schedule SET timezone = 'UTC' WHERE timezone IS NULL; +ALTER TABLE schedule MODIFY COLUMN timezone text NOT NULL; diff --git a/schema/pgsql/upgrades/0.2.0-schedule-timezone.sql b/schema/pgsql/upgrades/0.2.0-schedule-timezone.sql index ed93d2e0..7e41e81b 100644 --- a/schema/pgsql/upgrades/0.2.0-schedule-timezone.sql +++ b/schema/pgsql/upgrades/0.2.0-schedule-timezone.sql @@ -1 +1,12 @@ -ALTER TABLE schedule ADD COLUMN timezone text NOT NULL; +ALTER TABLE schedule ADD COLUMN timezone text; +UPDATE schedule SET timezone = ( + SELECT entry.timezone + FROM timeperiod_entry entry + INNER JOIN timeperiod ON timeperiod.id = entry.timeperiod_id + INNER JOIN rotation ON rotation.id = timeperiod.owned_by_rotation_id + WHERE rotation.schedule_id = schedule.id + ORDER BY entry.id + LIMIT 1 +); +UPDATE schedule SET timezone = 'UTC' WHERE timezone IS NULL; +ALTER TABLE schedule ALTER COLUMN timezone SET NOT NULL;