chore: add db query to retrieve workspaces & their agents (#14792)

Second PR for #14716.

Adds a query that, given a user ID, returns all the workspaces they own, that can also be `ActionRead` by the requesting user.

```
type GetWorkspacesAndAgentsByOwnerIDRow struct {
	WorkspaceID      uuid.UUID            `db:"workspace_id" json:"workspace_id"`
	WorkspaceName    string               `db:"workspace_name" json:"workspace_name"`
	JobStatus        ProvisionerJobStatus `db:"job_status" json:"job_status"`
	Transition       WorkspaceTransition  `db:"transition" json:"transition"`
	Agents           []AgentIDNamePair    `db:"agents" json:"agents"`
}
```
 `JobStatus` and `Transition` are set using the latest build/job of the workspace. Deleted workspaces are not included.
This commit is contained in:
Ethan
2024-11-01 14:36:12 +11:00
committed by GitHub
parent 31506e694b
commit f941e78079
15 changed files with 555 additions and 42 deletions
+3
View File
@@ -28,6 +28,9 @@ sql:
emit_enum_valid_method: true
emit_all_enum_values: true
overrides:
- db_type: "agent_id_name_pair"
go_type:
type: "AgentIDNamePair"
# Used in 'CustomRoles' query to filter by (name,organization_id)
- db_type: "name_organization_pair"
go_type: