From 0fedbd3bfc6fd215ece6c9e37afffb4e9838ccd9 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 15 Sep 2023 14:36:14 +0100 Subject: [PATCH 1/4] fix(coderd/database): migrate workspaces.last_used_at to timestamptz --- coderd/database/dump.sql | 2 +- .../000155_workspaces_last_used_at_timestamptz.down.sql | 6 ++++++ .../000155_workspaces_last_used_at_timestamptz.up.sql | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 coderd/database/migrations/000155_workspaces_last_used_at_timestamptz.down.sql create mode 100644 coderd/database/migrations/000155_workspaces_last_used_at_timestamptz.up.sql diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql index 3ee0ac7e19894..995fd93739d74 100644 --- a/coderd/database/dump.sql +++ b/coderd/database/dump.sql @@ -1046,7 +1046,7 @@ CREATE TABLE workspaces ( name character varying(64) NOT NULL, autostart_schedule text, ttl bigint, - last_used_at timestamp without time zone DEFAULT '0001-01-01 00:00:00'::timestamp without time zone NOT NULL, + last_used_at timestamp with time zone DEFAULT '0001-01-01 00:00:00+00'::timestamp with time zone NOT NULL, dormant_at timestamp with time zone, deleting_at timestamp with time zone ); diff --git a/coderd/database/migrations/000155_workspaces_last_used_at_timestamptz.down.sql b/coderd/database/migrations/000155_workspaces_last_used_at_timestamptz.down.sql new file mode 100644 index 0000000000000..32d0c15c5ddc8 --- /dev/null +++ b/coderd/database/migrations/000155_workspaces_last_used_at_timestamptz.down.sql @@ -0,0 +1,6 @@ +ALTER TABLE ONLY workspaces +ALTER COLUMN last_used_at + SET DATA TYPE timestamp + USING last_used_at::timestamptz, +ALTER COLUMN last_used_at + SET DEFAULT '0001-01-01 00:00:00'::timestamp; diff --git a/coderd/database/migrations/000155_workspaces_last_used_at_timestamptz.up.sql b/coderd/database/migrations/000155_workspaces_last_used_at_timestamptz.up.sql new file mode 100644 index 0000000000000..644ef947fda4c --- /dev/null +++ b/coderd/database/migrations/000155_workspaces_last_used_at_timestamptz.up.sql @@ -0,0 +1,6 @@ +ALTER TABLE ONLY workspaces +ALTER COLUMN last_used_at + SET DATA TYPE timestamptz + USING last_used_at::timestamp AT TIME ZONE 'UTC', +ALTER COLUMN last_used_at + SET DEFAULT '0001-01-01 00:00:00+00:00'::timestamptz; From 0fcfe57f3793a260a02b3ad54fd79f846657ca87 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 15 Sep 2023 14:59:35 +0100 Subject: [PATCH 2/4] stop using utc loc in test --- coderd/workspaces_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/coderd/workspaces_test.go b/coderd/workspaces_test.go index 3bf93b7b07326..43ca99deb2d9e 100644 --- a/coderd/workspaces_test.go +++ b/coderd/workspaces_test.go @@ -1515,12 +1515,8 @@ func TestWorkspaceFilterManual(t *testing.T) { t.Run("LastUsed", func(t *testing.T) { t.Parallel() - // nolint:gocritic // https://github.com/coder/coder/issues/9682 - db, ps := dbtestutil.NewDB(t, dbtestutil.WithTimezone("UTC")) client, _, api := coderdtest.NewWithAPI(t, &coderdtest.Options{ IncludeProvisionerDaemon: true, - Database: db, - Pubsub: ps, }) user := coderdtest.CreateFirstUser(t, client) authToken := uuid.NewString() From d5babdf4cde89f46be89166450d8f13fc60eab75 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 15 Sep 2023 15:01:50 +0100 Subject: [PATCH 3/4] stop using utc loc in test --- enterprise/coderd/templates_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/enterprise/coderd/templates_test.go b/enterprise/coderd/templates_test.go index 49dff3bd58565..ad961368ee928 100644 --- a/enterprise/coderd/templates_test.go +++ b/enterprise/coderd/templates_test.go @@ -13,7 +13,6 @@ import ( "github.com/coder/coder/v2/coderd/audit" "github.com/coder/coder/v2/coderd/coderdtest" "github.com/coder/coder/v2/coderd/database" - "github.com/coder/coder/v2/coderd/database/dbtestutil" "github.com/coder/coder/v2/coderd/rbac" "github.com/coder/coder/v2/codersdk" "github.com/coder/coder/v2/cryptorand" @@ -369,14 +368,10 @@ func TestTemplates(t *testing.T) { t.Run("UpdateLastUsedAt", func(t *testing.T) { t.Parallel() - // nolint:gocritic // https://github.com/coder/coder/issues/9682 - db, ps := dbtestutil.NewDB(t, dbtestutil.WithTimezone("UTC")) ctx := testutil.Context(t, testutil.WaitMedium) client, user := coderdenttest.New(t, &coderdenttest.Options{ Options: &coderdtest.Options{ IncludeProvisionerDaemon: true, - Database: db, - Pubsub: ps, }, LicenseOptions: &coderdenttest.LicenseOptions{ Features: license.Features{ From cd580fbef714d131a5cd066a2967df7c856719fe Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 15 Sep 2023 15:45:15 +0100 Subject: [PATCH 4/4] fixup! stop using utc loc in test --- .../000155_workspaces_last_used_at_timestamptz.down.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coderd/database/migrations/000155_workspaces_last_used_at_timestamptz.down.sql b/coderd/database/migrations/000155_workspaces_last_used_at_timestamptz.down.sql index 32d0c15c5ddc8..b594014d4b387 100644 --- a/coderd/database/migrations/000155_workspaces_last_used_at_timestamptz.down.sql +++ b/coderd/database/migrations/000155_workspaces_last_used_at_timestamptz.down.sql @@ -1,6 +1,6 @@ ALTER TABLE ONLY workspaces ALTER COLUMN last_used_at SET DATA TYPE timestamp - USING last_used_at::timestamptz, + USING last_used_at::timestamptz AT TIME ZONE 'UTC', ALTER COLUMN last_used_at SET DEFAULT '0001-01-01 00:00:00'::timestamp;