Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e755355

Browse files
committed
template queries
1 parent eb1a755 commit e755355

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
DROP TABLE workspace_agent_port_sharing;
2+
3+
ALTER TABLE templates DROP COLUMN max_port_sharing;
4+

coderd/database/migrations/000187_workspace_agent_port_sharing.up.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,22 @@ CREATE TABLE workspace_agent_port_sharing (
44
port integer NOT NULL,
55
share_level integer NOT NULL
66
);
7+
8+
ALTER TABLE templates ADD COLUMN max_port_sharing integer NOT NULL DEFAULT 0;
9+
10+
-- Update the template_with_users view by recreating it.
11+
DROP VIEW template_with_users;
12+
CREATE VIEW
13+
template_with_users
14+
AS
15+
SELECT
16+
templates.*,
17+
coalesce(visible_users.avatar_url, '') AS created_by_avatar_url,
18+
coalesce(visible_users.username, '') AS created_by_username
19+
FROM
20+
templates
21+
LEFT JOIN
22+
visible_users
23+
ON
24+
templates.created_by = visible_users.id;
25+
COMMENT ON VIEW template_with_users IS 'Joins in the username + avatar url of the created by user.';

coderd/database/modelqueries.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func (q *sqlQuerier) GetAuthorizedTemplates(ctx context.Context, arg GetTemplate
9090
&i.RequireActiveVersion,
9191
&i.Deprecated,
9292
&i.UseMaxTtl,
93+
&i.MaxPortSharing,
9394
&i.CreatedByAvatarURL,
9495
&i.CreatedByUsername,
9596
); err != nil {

coderd/database/queries/templates.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,11 @@ INSERT INTO
8383
user_acl,
8484
group_acl,
8585
display_name,
86-
allow_user_cancel_workspace_jobs
86+
allow_user_cancel_workspace_jobs,
87+
max_port_sharing
8788
)
8889
VALUES
89-
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14);
90+
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);
9091

9192
-- name: UpdateTemplateActiveVersionByID :exec
9293
UPDATE
@@ -116,7 +117,8 @@ SET
116117
icon = $5,
117118
display_name = $6,
118119
allow_user_cancel_workspace_jobs = $7,
119-
group_acl = $8
120+
group_acl = $8,
121+
max_port_sharing = $9
120122
WHERE
121123
id = $1
122124
;
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
-- name: CreateWorkspaceAgentPortShareLevel :exec
2-
INSERT INTO workspace_port_sharing (workspace_id, agent_name, port, share_level) VALUES ($1, $2, $3, $4);
2+
INSERT INTO workspace_agent_port_sharing (workspace_id, agent_name, port, share_level) VALUES ($1, $2, $3, $4);
33

44
-- name: GetWorkspaceAgentPortShareLevel :one
5-
SELECT * FROM workspace_port_sharing WHERE workspace_id = $1 AND agent_name = $2 AND port = $3;
5+
SELECT * FROM workspace_agent_port_sharing WHERE workspace_id = $1 AND agent_name = $2 AND port = $3;
66

77
-- name: UpdateWorkspaceAgentPortShareLevel :exec
8-
UPDATE workspace_port_sharing SET share_level = $1 WHERE workspace_id = $2 AND agent_name = $3 AND port = $4;
8+
UPDATE workspace_agent_port_sharing SET share_level = $1 WHERE workspace_id = $2 AND agent_name = $3 AND port = $4;
99

1010
-- name: DeleteWorkspaceAgentPortShareLevel :exec
11-
DELETE FROM workspace_port_sharing WHERE workspace_id = $1 AND agent_name = $2 AND port = $3;
12-
13-
11+
DELETE FROM workspace_agent_port_sharing WHERE workspace_id = $1 AND agent_name = $2 AND port = $3;

0 commit comments

Comments
 (0)