Skip to content

Commit 50f874c

Browse files
committed
add owner id
1 parent 3482d62 commit 50f874c

File tree

8 files changed

+43
-24
lines changed

8 files changed

+43
-24
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11152,11 +11152,12 @@ func (q *FakeQuerier) GetAuthorizedWorkspacesAndAgents(ctx context.Context, prep
1115211152
}
1115311153

1115411154
out = append(out, database.GetWorkspacesAndAgentsRow{
11155-
WorkspaceID: w.ID,
11156-
WorkspaceName: w.Name,
11157-
JobStatus: job.JobStatus,
11158-
Transition: build.Transition,
11159-
Agents: outAgents,
11155+
ID: w.ID,
11156+
Name: w.Name,
11157+
OwnerID: w.OwnerID,
11158+
JobStatus: job.JobStatus,
11159+
Transition: build.Transition,
11160+
Agents: outAgents,
1116011161
})
1116111162
}
1116211163

coderd/database/modelqueries.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,9 @@ func (q *sqlQuerier) GetAuthorizedWorkspacesAndAgents(ctx context.Context, prepa
333333
for rows.Next() {
334334
var i GetWorkspacesAndAgentsRow
335335
if err := rows.Scan(
336-
&i.WorkspaceID,
337-
&i.WorkspaceName,
336+
&i.ID,
337+
&i.Name,
338+
&i.OwnerID,
338339
&i.JobStatus,
339340
&i.Transition,
340341
pq.Array(&i.Agents),

coderd/database/querier_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ func TestGetAuthorizedWorkspacesAndAgents(t *testing.T) {
689689
require.NoError(t, err)
690690
require.Len(t, ownerRows, 4)
691691
for _, row := range ownerRows {
692-
switch row.WorkspaceID {
692+
switch row.ID {
693693
case pendingID:
694694
require.Len(t, row.Agents, 1)
695695
require.Equal(t, database.ProvisionerJobStatusPending, row.JobStatus)
@@ -705,7 +705,7 @@ func TestGetAuthorizedWorkspacesAndAgents(t *testing.T) {
705705
require.Equal(t, database.ProvisionerJobStatusSucceeded, row.JobStatus)
706706
require.Equal(t, database.WorkspaceTransitionDelete, row.Transition)
707707
default:
708-
t.Fatalf("unexpected workspace ID: %s", row.WorkspaceID)
708+
t.Fatalf("unexpected workspace ID: %s", row.ID)
709709
}
710710
}
711711
}

coderd/database/queries.sql.go

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

coderd/database/queries/workspaces.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,9 @@ UPDATE workspaces SET favorite = false WHERE id = @id;
690690

691691
-- name: GetWorkspacesAndAgents :many
692692
SELECT
693-
workspaces.id as workspace_id,
694-
workspaces.name as workspace_name,
693+
workspaces.id as id,
694+
workspaces.name as name,
695+
workspaces.owner_id as owner_id,
695696
job_status,
696697
transition,
697698
(array_agg(ROW(agent_id, agent_name)::agent_id_name_pair) FILTER (WHERE agent_id IS NOT NULL))::agent_id_name_pair[] as agents

coderd/database/types.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"database/sql/driver"
55
"encoding/json"
66
"fmt"
7+
"strings"
78
"time"
89

910
"github.com/google/uuid"
@@ -182,13 +183,25 @@ type AgentIDNamePair struct {
182183
}
183184

184185
func (p *AgentIDNamePair) Scan(src interface{}) error {
185-
switch v := src.(type) {
186+
var v string
187+
switch a := src.(type) {
186188
case []byte:
187-
return json.Unmarshal(v, &p)
189+
v = string(a)
188190
case string:
189-
return json.Unmarshal([]byte(v), &p)
191+
v = a
192+
default:
193+
return xerrors.Errorf("unexpected type %T", src)
190194
}
191-
return xerrors.Errorf("unexpected type %T", src)
195+
parts := strings.Split(strings.Trim(v, "()"), ",")
196+
if len(parts) != 2 {
197+
return xerrors.New("invalid format for AgentIDNamePair")
198+
}
199+
id, err := uuid.Parse(strings.TrimSpace(parts[0]))
200+
if err != nil {
201+
return err
202+
}
203+
p.ID, p.Name = id, strings.TrimSpace(parts[1])
204+
return nil
192205
}
193206

194207
func (p AgentIDNamePair) Value() (driver.Value, error) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy