mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
feat: add README parsing to template versions (#1500)
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/exp/slices"
|
||||
@ -1189,7 +1190,7 @@ func (q *fakeQuerier) InsertTemplateVersion(_ context.Context, arg database.Inse
|
||||
CreatedAt: arg.CreatedAt,
|
||||
UpdatedAt: arg.UpdatedAt,
|
||||
Name: arg.Name,
|
||||
Description: arg.Description,
|
||||
Readme: arg.Readme,
|
||||
JobID: arg.JobID,
|
||||
}
|
||||
q.templateVersions = append(q.templateVersions, version)
|
||||
@ -1478,7 +1479,7 @@ func (q *fakeQuerier) UpdateTemplateActiveVersionByID(_ context.Context, arg dat
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, template := range q.templates {
|
||||
if template.ID.String() != arg.ID.String() {
|
||||
if template.ID != arg.ID {
|
||||
continue
|
||||
}
|
||||
template.ActiveVersionID = arg.ActiveVersionID
|
||||
@ -1493,7 +1494,7 @@ func (q *fakeQuerier) UpdateTemplateDeletedByID(_ context.Context, arg database.
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, template := range q.templates {
|
||||
if template.ID.String() != arg.ID.String() {
|
||||
if template.ID != arg.ID {
|
||||
continue
|
||||
}
|
||||
template.Deleted = arg.Deleted
|
||||
@ -1508,7 +1509,7 @@ func (q *fakeQuerier) UpdateTemplateVersionByID(_ context.Context, arg database.
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, templateVersion := range q.templateVersions {
|
||||
if templateVersion.ID.String() != arg.ID.String() {
|
||||
if templateVersion.ID != arg.ID {
|
||||
continue
|
||||
}
|
||||
templateVersion.TemplateID = arg.TemplateID
|
||||
@ -1519,12 +1520,28 @@ func (q *fakeQuerier) UpdateTemplateVersionByID(_ context.Context, arg database.
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) UpdateTemplateVersionDescriptionByJobID(_ context.Context, arg database.UpdateTemplateVersionDescriptionByJobIDParams) error {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, templateVersion := range q.templateVersions {
|
||||
if templateVersion.JobID != arg.JobID {
|
||||
continue
|
||||
}
|
||||
templateVersion.Readme = arg.Readme
|
||||
templateVersion.UpdatedAt = time.Now()
|
||||
q.templateVersions[index] = templateVersion
|
||||
return nil
|
||||
}
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) UpdateProvisionerDaemonByID(_ context.Context, arg database.UpdateProvisionerDaemonByIDParams) error {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, daemon := range q.provisionerDaemons {
|
||||
if arg.ID.String() != daemon.ID.String() {
|
||||
if arg.ID != daemon.ID {
|
||||
continue
|
||||
}
|
||||
daemon.UpdatedAt = arg.UpdatedAt
|
||||
@ -1540,7 +1557,7 @@ func (q *fakeQuerier) UpdateWorkspaceAgentConnectionByID(_ context.Context, arg
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, agent := range q.provisionerJobAgents {
|
||||
if agent.ID.String() != arg.ID.String() {
|
||||
if agent.ID != arg.ID {
|
||||
continue
|
||||
}
|
||||
agent.FirstConnectedAt = arg.FirstConnectedAt
|
||||
@ -1557,7 +1574,7 @@ func (q *fakeQuerier) UpdateProvisionerJobByID(_ context.Context, arg database.U
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, job := range q.provisionerJobs {
|
||||
if arg.ID.String() != job.ID.String() {
|
||||
if arg.ID != job.ID {
|
||||
continue
|
||||
}
|
||||
job.UpdatedAt = arg.UpdatedAt
|
||||
@ -1572,7 +1589,7 @@ func (q *fakeQuerier) UpdateProvisionerJobWithCancelByID(_ context.Context, arg
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, job := range q.provisionerJobs {
|
||||
if arg.ID.String() != job.ID.String() {
|
||||
if arg.ID != job.ID {
|
||||
continue
|
||||
}
|
||||
job.CanceledAt = arg.CanceledAt
|
||||
@ -1587,7 +1604,7 @@ func (q *fakeQuerier) UpdateProvisionerJobWithCompleteByID(_ context.Context, ar
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, job := range q.provisionerJobs {
|
||||
if arg.ID.String() != job.ID.String() {
|
||||
if arg.ID != job.ID {
|
||||
continue
|
||||
}
|
||||
job.UpdatedAt = arg.UpdatedAt
|
||||
@ -1604,7 +1621,7 @@ func (q *fakeQuerier) UpdateWorkspaceAutostart(_ context.Context, arg database.U
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, workspace := range q.workspaces {
|
||||
if workspace.ID.String() != arg.ID.String() {
|
||||
if workspace.ID != arg.ID {
|
||||
continue
|
||||
}
|
||||
workspace.AutostartSchedule = arg.AutostartSchedule
|
||||
@ -1620,7 +1637,7 @@ func (q *fakeQuerier) UpdateWorkspaceAutostop(_ context.Context, arg database.Up
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, workspace := range q.workspaces {
|
||||
if workspace.ID.String() != arg.ID.String() {
|
||||
if workspace.ID != arg.ID {
|
||||
continue
|
||||
}
|
||||
workspace.AutostopSchedule = arg.AutostopSchedule
|
||||
@ -1636,7 +1653,7 @@ func (q *fakeQuerier) UpdateWorkspaceBuildByID(_ context.Context, arg database.U
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, workspaceBuild := range q.workspaceBuilds {
|
||||
if workspaceBuild.ID.String() != arg.ID.String() {
|
||||
if workspaceBuild.ID != arg.ID {
|
||||
continue
|
||||
}
|
||||
workspaceBuild.UpdatedAt = arg.UpdatedAt
|
||||
@ -1653,7 +1670,7 @@ func (q *fakeQuerier) UpdateWorkspaceDeletedByID(_ context.Context, arg database
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, workspace := range q.workspaces {
|
||||
if workspace.ID.String() != arg.ID.String() {
|
||||
if workspace.ID != arg.ID {
|
||||
continue
|
||||
}
|
||||
workspace.Deleted = arg.Deleted
|
||||
|
2
coderd/database/dump.sql
generated
2
coderd/database/dump.sql
generated
@ -234,7 +234,7 @@ CREATE TABLE template_versions (
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
updated_at timestamp with time zone NOT NULL,
|
||||
name character varying(64) NOT NULL,
|
||||
description character varying(1048576) NOT NULL,
|
||||
readme character varying(1048576) NOT NULL,
|
||||
job_id uuid NOT NULL
|
||||
);
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
ALTER TABLE template_versions RENAME README TO description;
|
@ -0,0 +1 @@
|
||||
ALTER TABLE template_versions RENAME description TO readme;
|
@ -446,7 +446,7 @@ type TemplateVersion struct {
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description string `db:"description" json:"description"`
|
||||
Readme string `db:"readme" json:"readme"`
|
||||
JobID uuid.UUID `db:"job_id" json:"job_id"`
|
||||
}
|
||||
|
||||
|
@ -103,6 +103,7 @@ type querier interface {
|
||||
UpdateTemplateActiveVersionByID(ctx context.Context, arg UpdateTemplateActiveVersionByIDParams) error
|
||||
UpdateTemplateDeletedByID(ctx context.Context, arg UpdateTemplateDeletedByIDParams) error
|
||||
UpdateTemplateVersionByID(ctx context.Context, arg UpdateTemplateVersionByIDParams) error
|
||||
UpdateTemplateVersionDescriptionByJobID(ctx context.Context, arg UpdateTemplateVersionDescriptionByJobIDParams) error
|
||||
UpdateUserHashedPassword(ctx context.Context, arg UpdateUserHashedPasswordParams) error
|
||||
UpdateUserProfile(ctx context.Context, arg UpdateUserProfileParams) (User, error)
|
||||
UpdateUserRoles(ctx context.Context, arg UpdateUserRolesParams) (User, error)
|
||||
|
@ -1830,7 +1830,7 @@ func (q *sqlQuerier) UpdateTemplateDeletedByID(ctx context.Context, arg UpdateTe
|
||||
|
||||
const getTemplateVersionByID = `-- name: GetTemplateVersionByID :one
|
||||
SELECT
|
||||
id, template_id, organization_id, created_at, updated_at, name, description, job_id
|
||||
id, template_id, organization_id, created_at, updated_at, name, readme, job_id
|
||||
FROM
|
||||
template_versions
|
||||
WHERE
|
||||
@ -1847,7 +1847,7 @@ func (q *sqlQuerier) GetTemplateVersionByID(ctx context.Context, id uuid.UUID) (
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.Readme,
|
||||
&i.JobID,
|
||||
)
|
||||
return i, err
|
||||
@ -1855,7 +1855,7 @@ func (q *sqlQuerier) GetTemplateVersionByID(ctx context.Context, id uuid.UUID) (
|
||||
|
||||
const getTemplateVersionByJobID = `-- name: GetTemplateVersionByJobID :one
|
||||
SELECT
|
||||
id, template_id, organization_id, created_at, updated_at, name, description, job_id
|
||||
id, template_id, organization_id, created_at, updated_at, name, readme, job_id
|
||||
FROM
|
||||
template_versions
|
||||
WHERE
|
||||
@ -1872,7 +1872,7 @@ func (q *sqlQuerier) GetTemplateVersionByJobID(ctx context.Context, jobID uuid.U
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.Readme,
|
||||
&i.JobID,
|
||||
)
|
||||
return i, err
|
||||
@ -1880,7 +1880,7 @@ func (q *sqlQuerier) GetTemplateVersionByJobID(ctx context.Context, jobID uuid.U
|
||||
|
||||
const getTemplateVersionByTemplateIDAndName = `-- name: GetTemplateVersionByTemplateIDAndName :one
|
||||
SELECT
|
||||
id, template_id, organization_id, created_at, updated_at, name, description, job_id
|
||||
id, template_id, organization_id, created_at, updated_at, name, readme, job_id
|
||||
FROM
|
||||
template_versions
|
||||
WHERE
|
||||
@ -1903,7 +1903,7 @@ func (q *sqlQuerier) GetTemplateVersionByTemplateIDAndName(ctx context.Context,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.Readme,
|
||||
&i.JobID,
|
||||
)
|
||||
return i, err
|
||||
@ -1911,7 +1911,7 @@ func (q *sqlQuerier) GetTemplateVersionByTemplateIDAndName(ctx context.Context,
|
||||
|
||||
const getTemplateVersionsByTemplateID = `-- name: GetTemplateVersionsByTemplateID :many
|
||||
SELECT
|
||||
id, template_id, organization_id, created_at, updated_at, name, description, job_id
|
||||
id, template_id, organization_id, created_at, updated_at, name, readme, job_id
|
||||
FROM
|
||||
template_versions
|
||||
WHERE
|
||||
@ -1972,7 +1972,7 @@ func (q *sqlQuerier) GetTemplateVersionsByTemplateID(ctx context.Context, arg Ge
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.Readme,
|
||||
&i.JobID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@ -1997,11 +1997,11 @@ INSERT INTO
|
||||
created_at,
|
||||
updated_at,
|
||||
"name",
|
||||
description,
|
||||
readme,
|
||||
job_id
|
||||
)
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id, template_id, organization_id, created_at, updated_at, name, description, job_id
|
||||
($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id, template_id, organization_id, created_at, updated_at, name, readme, job_id
|
||||
`
|
||||
|
||||
type InsertTemplateVersionParams struct {
|
||||
@ -2011,7 +2011,7 @@ type InsertTemplateVersionParams struct {
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description string `db:"description" json:"description"`
|
||||
Readme string `db:"readme" json:"readme"`
|
||||
JobID uuid.UUID `db:"job_id" json:"job_id"`
|
||||
}
|
||||
|
||||
@ -2023,7 +2023,7 @@ func (q *sqlQuerier) InsertTemplateVersion(ctx context.Context, arg InsertTempla
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
arg.Name,
|
||||
arg.Description,
|
||||
arg.Readme,
|
||||
arg.JobID,
|
||||
)
|
||||
var i TemplateVersion
|
||||
@ -2034,7 +2034,7 @@ func (q *sqlQuerier) InsertTemplateVersion(ctx context.Context, arg InsertTempla
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.Readme,
|
||||
&i.JobID,
|
||||
)
|
||||
return i, err
|
||||
@ -2061,6 +2061,26 @@ func (q *sqlQuerier) UpdateTemplateVersionByID(ctx context.Context, arg UpdateTe
|
||||
return err
|
||||
}
|
||||
|
||||
const updateTemplateVersionDescriptionByJobID = `-- name: UpdateTemplateVersionDescriptionByJobID :exec
|
||||
UPDATE
|
||||
template_versions
|
||||
SET
|
||||
readme = $2,
|
||||
updated_at = now()
|
||||
WHERE
|
||||
job_id = $1
|
||||
`
|
||||
|
||||
type UpdateTemplateVersionDescriptionByJobIDParams struct {
|
||||
JobID uuid.UUID `db:"job_id" json:"job_id"`
|
||||
Readme string `db:"readme" json:"readme"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) UpdateTemplateVersionDescriptionByJobID(ctx context.Context, arg UpdateTemplateVersionDescriptionByJobIDParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateTemplateVersionDescriptionByJobID, arg.JobID, arg.Readme)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAllUserRoles = `-- name: GetAllUserRoles :one
|
||||
SELECT
|
||||
-- username is returned just to help for logging purposes
|
||||
|
@ -66,7 +66,7 @@ INSERT INTO
|
||||
created_at,
|
||||
updated_at,
|
||||
"name",
|
||||
description,
|
||||
readme,
|
||||
job_id
|
||||
)
|
||||
VALUES
|
||||
@ -80,3 +80,12 @@ SET
|
||||
updated_at = $3
|
||||
WHERE
|
||||
id = $1;
|
||||
|
||||
-- name: UpdateTemplateVersionDescriptionByJobID :exec
|
||||
UPDATE
|
||||
template_versions
|
||||
SET
|
||||
readme = $2,
|
||||
updated_at = now()
|
||||
WHERE
|
||||
job_id = $1;
|
||||
|
Reference in New Issue
Block a user