Skip to content

Commit aea3b3b

Browse files
authored
feat: add template version creator (#2991)
1 parent 6ef8a62 commit aea3b3b

File tree

14 files changed

+106
-16
lines changed

14 files changed

+106
-16
lines changed

coderd/audit/diff_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ func TestDiff(t *testing.T) {
114114
UpdatedAt: time.Now(),
115115
OrganizationID: uuid.UUID{3},
116116
Name: "rust",
117+
CreatedBy: uuid.UUID{4},
117118
},
118119
exp: audit.Map{
119120
"id": uuid.UUID{1}.String(),
120121
"template_id": uuid.UUID{2}.String(),
121122
"organization_id": uuid.UUID{3}.String(),
122123
"name": "rust",
124+
"created_by": uuid.UUID{4}.String(),
123125
},
124126
},
125127
{
@@ -132,11 +134,13 @@ func TestDiff(t *testing.T) {
132134
UpdatedAt: time.Now(),
133135
OrganizationID: uuid.UUID{3},
134136
Name: "rust",
137+
CreatedBy: uuid.UUID{4},
135138
},
136139
exp: audit.Map{
137140
"id": uuid.UUID{1}.String(),
138141
"organization_id": uuid.UUID{3}.String(),
139142
"name": "rust",
143+
"created_by": uuid.UUID{4}.String(),
140144
},
141145
},
142146
})

coderd/audit/table.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ var AuditableResources = auditMap(map[any]map[string]Action{
8383
"name": ActionTrack,
8484
"readme": ActionTrack,
8585
"job_id": ActionIgnore, // Not helpful in a diff because jobs aren't tracked in audit logs.
86+
"created_by": ActionTrack,
8687
},
8788
&database.User{}: {
8889
"id": ActionTrack,

coderd/database/databasefake/databasefake.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,7 @@ func (q *fakeQuerier) InsertTemplateVersion(_ context.Context, arg database.Inse
15111511
Name: arg.Name,
15121512
Readme: arg.Readme,
15131513
JobID: arg.JobID,
1514+
CreatedBy: arg.CreatedBy,
15141515
}
15151516
q.templateVersions = append(q.templateVersions, version)
15161517
return version, nil

coderd/database/dump.sql

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE ONLY template_versions DROP COLUMN IF EXISTS created_by;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ALTER TABLE ONLY template_versions ADD COLUMN IF NOT EXISTS created_by uuid REFERENCES users (id) ON DELETE RESTRICT;
2+
3+
UPDATE
4+
template_versions
5+
SET
6+
created_by = (
7+
SELECT created_by FROM templates
8+
WHERE template_versions.template_id = templates.id
9+
LIMIT 1
10+
)
11+
WHERE
12+
created_by IS NULL;
13+
14+
ALTER TABLE ONLY template_versions ALTER COLUMN created_by SET NOT NULL;

coderd/database/models.go

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

coderd/database/queries.sql.go

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

coderd/database/queries/templateversions.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ INSERT INTO
7070
updated_at,
7171
"name",
7272
readme,
73-
job_id
73+
job_id,
74+
created_by
7475
)
7576
VALUES
76-
($1, $2, $3, $4, $5, $6, $7, $8) RETURNING *;
77+
($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *;
7778

7879
-- name: UpdateTemplateVersionByID :exec
7980
UPDATE

coderd/templates.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ func (api *API) postTemplateByOrganization(rw http.ResponseWriter, r *http.Reque
209209
UUID: dbTemplate.ID,
210210
Valid: true,
211211
},
212+
UpdatedAt: database.Now(),
212213
})
213214
if err != nil {
214215
return xerrors.Errorf("insert template version: %s", err)

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