fix(coderd/database): migrate workspaces.last_used_at to timestamptz#9699
Merged
Conversation
mafredri
approved these changes
Sep 15, 2023
| ALTER TABLE ONLY workspaces | ||
| ALTER COLUMN last_used_at | ||
| SET DATA TYPE timestamp | ||
| USING last_used_at::timestamptz, |
Member
There was a problem hiding this comment.
If we want to be 100% correct, this could use an AT TIME ZONE 'UTC' too because during the up migration we are changing the time (correctly) if the db time zone is non-UTC.
This demonstrates how the timestamp would be coerced into the wrong time without
woop=# create temp table testy (ts timestamp, tsz timestamptz);
CREATE TABLE
woop=# insert into testy (ts, tsz) values ('0001-01-01 00:00:00+00', '0001-01-01 00:00:00+00'); select * from testy;
INSERT 0 1
ts | tsz
---------------------+------------------------------
0001-01-01 00:00:00 | 0001-01-01 01:39:49+01:39:49
(1 row)
woop=# update testy set ts = tsz::timestamptz; select * from testy;
UPDATE 1
ts | tsz
---------------------+------------------------------
0001-01-01 01:39:49 | 0001-01-01 01:39:49+01:39:49
(1 row)
Whereas with the time zone change:
woop=# truncate table testy;
TRUNCATE TABLE
woop=# insert into testy (ts, tsz) values ('0001-01-01 00:00:00+00', '0001-01-01 00:00:00+00'); select * from testy;
INSERT 0 1
ts | tsz
---------------------+------------------------------
0001-01-01 00:00:00 | 0001-01-01 01:39:49+01:39:49
(1 row)
woop=# update testy set ts = tsz at time zone 'utc'; select * from testy;
UPDATE 1
ts | tsz
---------------------+------------------------------
0001-01-01 00:00:00 | 0001-01-01 01:39:49+01:39:49
(1 row)
…ed-at-timestamptz
…ed-at-timestamptz
…ed-at-timestamptz
…ed-at-timestamptz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Partially resolves #9682 (will update users.last_seen_at in a separate PR).