Skip to content

Commit 5766918

Browse files
committed
Get previous template version
1 parent 883cf8a commit 5766918

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

coderd/database/databasefake/databasefake.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,25 @@ func (q *fakeQuerier) GetTemplateVersionByJobID(_ context.Context, jobID uuid.UU
17171717
return database.TemplateVersion{}, sql.ErrNoRows
17181718
}
17191719

1720+
func (q *fakeQuerier) GetPreviousTemplateVersionByID(_ context.Context, id uuid.UUID) (database.TemplateVersion, error) {
1721+
q.mutex.RLock()
1722+
defer q.mutex.RUnlock()
1723+
1724+
var previousIndex = -1
1725+
for index, templateVersion := range q.templateVersions {
1726+
if templateVersion.ID != id {
1727+
continue
1728+
}
1729+
previousIndex = index - 1
1730+
}
1731+
1732+
if previousIndex < 0 {
1733+
return database.TemplateVersion{}, sql.ErrNoRows
1734+
}
1735+
1736+
return q.templateVersions[previousIndex], nil
1737+
}
1738+
17201739
func (q *fakeQuerier) GetParameterSchemasByJobID(_ context.Context, jobID uuid.UUID) ([]database.ParameterSchema, error) {
17211740
q.mutex.RLock()
17221741
defer q.mutex.RUnlock()

coderd/database/querier.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: 28 additions & 0 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,13 @@ SET
110110
updated_at = $3
111111
WHERE
112112
job_id = $1;
113+
114+
-- name: GetPreviousTemplateVersionByID :one
115+
SELECT
116+
*
117+
FROM
118+
template_versions
119+
WHERE
120+
created_at < (SELECT created_at FROM template_versions WHERE template_versions.id = @id)
121+
ORDER BY created_at DESC
122+
LIMIT 1;

0 commit comments

Comments
 (0)