Skip to content

Commit d7a0abf

Browse files
committed
chore: rename template_with_user to template_with_names
1 parent 48f2ecf commit d7a0abf

File tree

8 files changed

+38
-27
lines changed

8 files changed

+38
-27
lines changed

cli/templatelist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func (r *RootCmd) templateList() *serpent.Command {
1414
orgContext := NewOrganizationContext()
1515
formatter := cliui.NewOutputFormatter(
16-
cliui.TableFormat([]templateTableRow{}, []string{"name", "last updated", "used by"}),
16+
cliui.TableFormat([]templateTableRow{}, []string{"name", "organization name", "last updated", "used by"}),
1717
cliui.JSONFormat(),
1818
)
1919

coderd/database/dbmem/dbmem.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ func (q *FakeQuerier) getLatestWorkspaceBuildByWorkspaceIDNoLock(_ context.Conte
515515
func (q *FakeQuerier) getTemplateByIDNoLock(_ context.Context, id uuid.UUID) (database.Template, error) {
516516
for _, template := range q.templates {
517517
if template.ID == id {
518-
return q.templateWithUserNoLock(template), nil
518+
return q.templateWithNameNoLock(template), nil
519519
}
520520
}
521521
return database.Template{}, sql.ErrNoRows
@@ -524,26 +524,36 @@ func (q *FakeQuerier) getTemplateByIDNoLock(_ context.Context, id uuid.UUID) (da
524524
func (q *FakeQuerier) templatesWithUserNoLock(tpl []database.TemplateTable) []database.Template {
525525
cpy := make([]database.Template, 0, len(tpl))
526526
for _, t := range tpl {
527-
cpy = append(cpy, q.templateWithUserNoLock(t))
527+
cpy = append(cpy, q.templateWithNameNoLock(t))
528528
}
529529
return cpy
530530
}
531531

532-
func (q *FakeQuerier) templateWithUserNoLock(tpl database.TemplateTable) database.Template {
532+
func (q *FakeQuerier) templateWithNameNoLock(tpl database.TemplateTable) database.Template {
533533
var user database.User
534534
for _, _user := range q.users {
535535
if _user.ID == tpl.CreatedBy {
536536
user = _user
537537
break
538538
}
539539
}
540-
var withUser database.Template
540+
541+
var org database.Organization
542+
for _, _org := range q.organizations {
543+
if _org.ID == tpl.OrganizationID {
544+
org = _org
545+
break
546+
}
547+
}
548+
549+
var withNames database.Template
541550
// This is a cheeky way to copy the fields over without explicitly listing them all.
542551
d, _ := json.Marshal(tpl)
543-
_ = json.Unmarshal(d, &withUser)
544-
withUser.CreatedByUsername = user.Username
545-
withUser.CreatedByAvatarURL = user.AvatarURL
546-
return withUser
552+
_ = json.Unmarshal(d, &withNames)
553+
withNames.CreatedByUsername = user.Username
554+
withNames.CreatedByAvatarURL = user.AvatarURL
555+
withNames.OrganizationName = org.Name
556+
return withNames
547557
}
548558

549559
func (q *FakeQuerier) templateVersionWithUserNoLock(tpl database.TemplateVersionTable) database.TemplateVersion {
@@ -3675,7 +3685,7 @@ func (q *FakeQuerier) GetTemplateByOrganizationAndName(_ context.Context, arg da
36753685
if template.Deleted != arg.Deleted {
36763686
continue
36773687
}
3678-
return q.templateWithUserNoLock(template), nil
3688+
return q.templateWithNameNoLock(template), nil
36793689
}
36803690
return database.Template{}, sql.ErrNoRows
36813691
}
@@ -9323,7 +9333,7 @@ func (q *FakeQuerier) GetAuthorizedTemplates(ctx context.Context, arg database.G
93239333

93249334
var templates []database.Template
93259335
for _, templateTable := range q.templates {
9326-
template := q.templateWithUserNoLock(templateTable)
9336+
template := q.templateWithNameNoLock(templateTable)
93279337
if prepared != nil && prepared.Authorize(ctx, template.RBACObject()) != nil {
93289338
continue
93299339
}

coderd/database/dump.sql

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

coderd/database/gentest/models_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestViewSubsetTemplate(t *testing.T) {
3232
tableFields := allFields(table)
3333
joinedFields := allFields(joined)
3434
if !assert.Subset(t, fieldNames(joinedFields), fieldNames(tableFields), "table is not subset") {
35-
t.Log("Some fields were added to the Template Table without updating the 'template_with_users' view.")
35+
t.Log("Some fields were added to the Template Table without updating the 'template_with_names' view.")
3636
t.Log("See migration 000138_join_users.up.sql to create the view.")
3737
}
3838
}

coderd/database/migrations/000222_template_organization_name.up.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
-- Update the template_with_users view by recreating it.
22
DROP VIEW template_with_users;
33

4+
-- Renaming template_with_users -> template_with_names
45
CREATE VIEW
5-
template_with_users
6+
template_with_names
67
AS
78
SELECT
89
templates.*,
@@ -20,4 +21,4 @@ FROM
2021
ON templates.organization_id = organizations.id
2122
;
2223

23-
COMMENT ON VIEW template_with_users IS 'Joins in the display name information such as username, avatar, and organization name.';
24+
COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.';

coderd/database/queries.sql.go

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

coderd/database/queries/templates.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
SELECT
33
*
44
FROM
5-
template_with_users
5+
template_with_names
66
WHERE
77
id = $1
88
LIMIT
@@ -12,7 +12,7 @@ LIMIT
1212
SELECT
1313
*
1414
FROM
15-
template_with_users AS templates
15+
template_with_names AS templates
1616
WHERE
1717
-- Optionally include deleted templates
1818
templates.deleted = @deleted
@@ -54,7 +54,7 @@ ORDER BY (name, id) ASC
5454
SELECT
5555
*
5656
FROM
57-
template_with_users AS templates
57+
template_with_names AS templates
5858
WHERE
5959
organization_id = @organization_id
6060
AND deleted = @deleted
@@ -63,7 +63,7 @@ LIMIT
6363
1;
6464

6565
-- name: GetTemplates :many
66-
SELECT * FROM template_with_users AS templates
66+
SELECT * FROM template_with_names AS templates
6767
ORDER BY (name, id) ASC
6868
;
6969

coderd/database/sqlc.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ sql:
5555
- column: "templates.group_acl"
5656
go_type:
5757
type: "TemplateACL"
58-
- column: "template_with_users.user_acl"
58+
- column: "template_with_names.user_acl"
5959
go_type:
6060
type: "TemplateACL"
61-
- column: "template_with_users.group_acl"
61+
- column: "template_with_names.group_acl"
6262
go_type:
6363
type: "TemplateACL"
6464
- column: "template_usage_stats.app_usage_mins"
@@ -72,7 +72,7 @@ sql:
7272
type: "[]byte"
7373
rename:
7474
template: TemplateTable
75-
template_with_user: Template
75+
template_with_name: Template
7676
workspace_build: WorkspaceBuildTable
7777
workspace_build_with_user: WorkspaceBuild
7878
template_version: TemplateVersionTable

0 commit comments

Comments
 (0)