Skip to content

Commit 1cc5e6d

Browse files
committed
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'**.
1 parent 7830d9e commit 1cc5e6d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

schema/mysql/upgrades/002.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
ALTER TABLE schedule ADD COLUMN timezone text NOT NULL;
1+
ALTER TABLE schedule ADD COLUMN timezone text;
2+
UPDATE schedule s SET timezone = (SELECT tpe.timezone FROM timeperiod_entry tpe INNER JOIN timeperiod tp ON tp.id = tpe.timeperiod_id INNER JOIN rotation r ON r.id = tp.owned_by_rotation_id WHERE r.schedule_id = s.id ORDER BY tpe.id LIMIT 1);
3+
UPDATE schedule SET timezone = 'UTC' WHERE timezone IS NULL;
4+
ALTER TABLE schedule MODIFY COLUMN timezone text NOT NULL;

schema/pgsql/upgrades/002.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
ALTER TABLE schedule ADD COLUMN timezone text NOT NULL;
1+
ALTER TABLE schedule ADD COLUMN timezone text;
2+
UPDATE schedule s SET timezone = (SELECT tpe.timezone FROM timeperiod_entry tpe INNER JOIN timeperiod tp ON tp.id = tpe.timeperiod_id INNER JOIN rotation r ON r.id = tp.owned_by_rotation_id WHERE r.schedule_id = s.id ORDER BY tpe.id LIMIT 1);
3+
UPDATE schedule SET timezone = 'UTC' WHERE timezone IS NULL;
4+
ALTER TABLE schedule ALTER COLUMN timezone SET NOT NULL;

0 commit comments

Comments
 (0)