mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: join owner, template, and org in new workspace view (#15116)
Joins in fields like `username`, `avatar_url`, `organization_name`, `template_name` to `workspaces` via a **view**. The view must be maintained moving forward, but this prevents needing to add RBAC permissions to fetch related workspace fields.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
DROP VIEW workspaces_expanded;
|
||||
@@ -0,0 +1,33 @@
|
||||
CREATE VIEW
|
||||
workspaces_expanded
|
||||
AS
|
||||
SELECT
|
||||
workspaces.*,
|
||||
-- Owner
|
||||
visible_users.avatar_url AS owner_avatar_url,
|
||||
visible_users.username AS owner_username,
|
||||
-- Organization
|
||||
organizations.name AS organization_name,
|
||||
organizations.display_name AS organization_display_name,
|
||||
organizations.icon AS organization_icon,
|
||||
organizations.description AS organization_description,
|
||||
-- Template
|
||||
templates.name AS template_name,
|
||||
templates.display_name AS template_display_name,
|
||||
templates.icon AS template_icon,
|
||||
templates.description AS template_description
|
||||
FROM
|
||||
workspaces
|
||||
INNER JOIN
|
||||
visible_users
|
||||
ON
|
||||
workspaces.owner_id = visible_users.id
|
||||
INNER JOIN
|
||||
organizations
|
||||
ON workspaces.organization_id = organizations.id
|
||||
INNER JOIN
|
||||
templates
|
||||
ON workspaces.template_id = templates.id
|
||||
;
|
||||
|
||||
COMMENT ON VIEW workspaces_expanded IS 'Joins in the display name information such as username, avatar, and organization name.';
|
||||
Reference in New Issue
Block a user