feat(coderd/database): add api_version to provisioner_daemons table (#11204)

Adds column api_version to the provisioner_daemons table.
This is distinct from the coderd version, and is used to handle breaking changes in the provisioner daemon API.
This commit is contained in:
Cian Johnston
2023-12-14 12:52:41 +00:00
committed by GitHub
parent b779655f01
commit 5b0e6bfa2a
7 changed files with 38 additions and 10 deletions

View File

@ -3019,7 +3019,7 @@ func (q *sqlQuerier) DeleteOldProvisionerDaemons(ctx context.Context) error {
const getProvisionerDaemons = `-- name: GetProvisionerDaemons :many
SELECT
id, created_at, name, provisioners, replica_id, tags, last_seen_at, version
id, created_at, name, provisioners, replica_id, tags, last_seen_at, version, api_version
FROM
provisioner_daemons
`
@ -3042,6 +3042,7 @@ func (q *sqlQuerier) GetProvisionerDaemons(ctx context.Context) ([]ProvisionerDa
&i.Tags,
&i.LastSeenAt,
&i.Version,
&i.APIVersion,
); err != nil {
return nil, err
}
@ -3065,7 +3066,8 @@ INSERT INTO
provisioners,
tags,
last_seen_at,
"version"
"version",
api_version
)
VALUES (
gen_random_uuid(),
@ -3074,16 +3076,18 @@ VALUES (
$3,
$4,
$5,
$6
$6,
$7
) ON CONFLICT("name", lower((tags ->> 'owner'::text))) DO UPDATE SET
provisioners = $3,
tags = $4,
last_seen_at = $5,
"version" = $6
"version" = $6,
api_version = $7
WHERE
-- Only ones with the same tags are allowed clobber
provisioner_daemons.tags <@ $4 :: jsonb
RETURNING id, created_at, name, provisioners, replica_id, tags, last_seen_at, version
RETURNING id, created_at, name, provisioners, replica_id, tags, last_seen_at, version, api_version
`
type UpsertProvisionerDaemonParams struct {
@ -3093,6 +3097,7 @@ type UpsertProvisionerDaemonParams struct {
Tags StringMap `db:"tags" json:"tags"`
LastSeenAt sql.NullTime `db:"last_seen_at" json:"last_seen_at"`
Version string `db:"version" json:"version"`
APIVersion string `db:"api_version" json:"api_version"`
}
func (q *sqlQuerier) UpsertProvisionerDaemon(ctx context.Context, arg UpsertProvisionerDaemonParams) (ProvisionerDaemon, error) {
@ -3103,6 +3108,7 @@ func (q *sqlQuerier) UpsertProvisionerDaemon(ctx context.Context, arg UpsertProv
arg.Tags,
arg.LastSeenAt,
arg.Version,
arg.APIVersion,
)
var i ProvisionerDaemon
err := row.Scan(
@ -3114,6 +3120,7 @@ func (q *sqlQuerier) UpsertProvisionerDaemon(ctx context.Context, arg UpsertProv
&i.Tags,
&i.LastSeenAt,
&i.Version,
&i.APIVersion,
)
return i, err
}