Skip to content

Commit 6dc9508

Browse files
committed
remove deadline usage from queries
1 parent c32f811 commit 6dc9508

File tree

16 files changed

+77
-97
lines changed

16 files changed

+77
-97
lines changed

coderd/activitybump_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ func TestWorkspaceActivityBump(t *testing.T) {
7575
}
7676

7777
err := db.UpdateWorkspaceBuildDeadlineByID(ctx, database.UpdateWorkspaceBuildDeadlineByIDParams{
78-
ID: workspace.LatestBuild.ID,
79-
UpdatedAt: dbtime.Now(),
80-
// Make the deadline really close so it needs to be bumped immediately.
81-
Deadline: dbtime.Now().Add(time.Minute),
78+
ID: workspace.LatestBuild.ID,
79+
UpdatedAt: dbtime.Now(),
8280
MaxDeadline: maxDeadline,
8381
})
8482
require.NoError(t, err)

coderd/autobuild/lifecycle_executor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ func isEligibleForAutostop(ws database.Workspace, build database.WorkspaceBuild,
389389

390390
// A workspace must be started in order for it to be auto-stopped.
391391
return build.Transition == database.WorkspaceTransitionStart &&
392-
!build.Deadline.IsZero() &&
392+
!build.MaxDeadline.IsZero() &&
393393
// We do not want to stop a workspace prior to it breaching its deadline.
394-
!currentTick.Before(build.Deadline)
394+
!currentTick.Before(build.MaxDeadline)
395395
}
396396

397397
// isEligibleForDormantStop returns true if the workspace should be dormant

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,6 @@ func (s *MethodTestSuite) TestWorkspace() {
15571557
check.Args(database.UpdateWorkspaceBuildDeadlineByIDParams{
15581558
ID: build.ID,
15591559
UpdatedAt: build.UpdatedAt,
1560-
Deadline: build.Deadline,
15611560
}).Asserts(ws, policy.ActionUpdate)
15621561
}))
15631562
s.Run("SoftDeleteWorkspaceByID", s.Subtest(func(db database.Store, check *expects) {

coderd/database/dbgen/dbgen.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ func WorkspaceBuild(t testing.TB, db database.Store, orig database.WorkspaceBuil
233233
InitiatorID: takeFirst(orig.InitiatorID, uuid.New()),
234234
JobID: takeFirst(orig.JobID, uuid.New()),
235235
ProvisionerState: takeFirstSlice(orig.ProvisionerState, []byte{}),
236-
Deadline: takeFirst(orig.Deadline, dbtime.Now().Add(time.Hour)),
237236
MaxDeadline: takeFirst(orig.MaxDeadline, time.Time{}),
238237
Reason: takeFirst(orig.Reason, database.BuildReasonInitiator),
239238
})

coderd/database/dbmem/dbmem.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5500,8 +5500,8 @@ func (q *FakeQuerier) GetWorkspacesEligibleForTransition(ctx context.Context, no
55005500
}
55015501

55025502
if build.Transition == database.WorkspaceTransitionStart &&
5503-
!build.Deadline.IsZero() &&
5504-
build.Deadline.Before(now) &&
5503+
!build.MaxDeadline.IsZero() &&
5504+
build.MaxDeadline.Before(now) &&
55055505
!workspace.DormantAt.Valid {
55065506
workspaces = append(workspaces, workspace)
55075507
continue
@@ -6580,7 +6580,6 @@ func (q *FakeQuerier) InsertWorkspaceBuild(_ context.Context, arg database.Inser
65806580
InitiatorID: arg.InitiatorID,
65816581
JobID: arg.JobID,
65826582
ProvisionerState: arg.ProvisionerState,
6583-
Deadline: arg.Deadline,
65846583
MaxDeadline: arg.MaxDeadline,
65856584
Reason: arg.Reason,
65866585
}
@@ -7876,7 +7875,6 @@ func (q *FakeQuerier) UpdateWorkspaceBuildDeadlineByID(_ context.Context, arg da
78767875
if build.ID != arg.ID {
78777876
continue
78787877
}
7879-
build.Deadline = arg.Deadline
78807878
build.MaxDeadline = arg.MaxDeadline
78817879
build.UpdatedAt = arg.UpdatedAt
78827880
q.workspaceBuilds[idx] = build

coderd/database/dump.sql

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/migrations/000209_workspace_deadline_view.up.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,23 @@ WHERE
2020
WHERE
2121
workspace_builds.workspace_id = workspaces.id
2222
);
23+
24+
ALTER TABLE workspace_builds RENAME COLUMN deadline TO deadline_deprecated;
25+
26+
DROP VIEW workspace_build_with_user;
27+
28+
CREATE VIEW
29+
workspace_build_with_user
30+
AS
31+
SELECT
32+
workspace_builds.*,
33+
coalesce(visible_users.avatar_url, '') AS initiator_by_avatar_url,
34+
coalesce(visible_users.username, '') AS initiator_by_username
35+
FROM
36+
workspace_builds
37+
LEFT JOIN
38+
visible_users
39+
ON
40+
workspace_builds.initiator_id = visible_users.id;
41+
42+
COMMENT ON VIEW workspace_build_with_user IS 'Joins in the username + avatar url of the initiated by user.';

coderd/database/models.go

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)