forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkspaceagentcontext.sql
More file actions
74 lines (70 loc) · 1.97 KB
/
Copy pathworkspaceagentcontext.sql
File metadata and controls
74 lines (70 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
-- name: UpsertWorkspaceAgentContextSnapshot :one
INSERT INTO workspace_agent_context_snapshots (
workspace_agent_id,
version,
aggregate_hash,
snapshot_error,
received_at
) VALUES (
@workspace_agent_id,
@version,
@aggregate_hash,
@snapshot_error,
@received_at
)
ON CONFLICT (workspace_agent_id) DO UPDATE SET
version = EXCLUDED.version,
aggregate_hash = EXCLUDED.aggregate_hash,
snapshot_error = EXCLUDED.snapshot_error,
received_at = EXCLUDED.received_at
RETURNING *;
-- name: UpsertWorkspaceAgentContextResource :one
INSERT INTO workspace_agent_context_resources (
workspace_agent_id,
source,
body_kind,
body,
content_hash,
size_bytes,
status,
error,
source_path,
created_at,
updated_at
) VALUES (
@workspace_agent_id,
@source,
@body_kind,
@body,
@content_hash,
@size_bytes,
@status,
@error,
@source_path,
@now,
@now
)
ON CONFLICT (workspace_agent_id, source) DO UPDATE SET
body_kind = EXCLUDED.body_kind,
body = EXCLUDED.body,
content_hash = EXCLUDED.content_hash,
size_bytes = EXCLUDED.size_bytes,
status = EXCLUDED.status,
error = EXCLUDED.error,
source_path = EXCLUDED.source_path,
updated_at = EXCLUDED.updated_at
RETURNING *;
-- name: DeleteStaleWorkspaceAgentContextResources :exec
-- Deletes any resources for the agent whose source is not in the
-- supplied active set. Atomic alongside the snapshot upsert so the
-- stored snapshot and resource rows always agree.
DELETE FROM workspace_agent_context_resources
WHERE workspace_agent_id = @workspace_agent_id
AND NOT (source = ANY(@active_sources :: text[]));
-- name: GetLatestWorkspaceAgentContextSnapshot :one
SELECT * FROM workspace_agent_context_snapshots
WHERE workspace_agent_id = @workspace_agent_id;
-- name: ListWorkspaceAgentContextResources :many
SELECT * FROM workspace_agent_context_resources
WHERE workspace_agent_id = @workspace_agent_id
ORDER BY source ASC;