Skip to content

Commit

Permalink
cast sqlc queries to deployment_name
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Mar 13, 2024
1 parent 287c497 commit ddd6890
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
18 changes: 9 additions & 9 deletions backend/controller/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,9 @@ func (d *DAL) GetDeployment(ctx context.Context, name model.DeploymentName) (*mo
// ErrConflict will be returned if a runner with the same endpoint and a
// different key already exists.
func (d *DAL) UpsertRunner(ctx context.Context, runner Runner) error {
var pgDeploymentName optional.Option[string]
if dkey, ok := runner.Deployment.Get(); ok {
pgDeploymentName = optional.Some(dkey.String())
var pgDeploymentName optional.Option[model.DeploymentName]
if dname, ok := runner.Deployment.Get(); ok {
pgDeploymentName = optional.Some(dname)
}
attrBytes, err := json.Marshal(runner.Labels)
if err != nil {
Expand Down Expand Up @@ -612,7 +612,7 @@ func (p *postgresClaim) Rollback(ctx context.Context) error {
func (p *postgresClaim) Runner() Runner { return p.runner }

// SetDeploymentReplicas activates the given deployment.
func (d *DAL) SetDeploymentReplicas(ctx context.Context, key model.DeploymentName, minReplicas int) error {
func (d *DAL) SetDeploymentReplicas(ctx context.Context, name model.DeploymentName, minReplicas int) error {
// Start the transaction
tx, err := d.db.Begin(ctx)
if err != nil {
Expand All @@ -621,18 +621,18 @@ func (d *DAL) SetDeploymentReplicas(ctx context.Context, key model.DeploymentNam

defer tx.CommitOrRollback(ctx, &err)

deployment, err := d.db.GetDeployment(ctx, key)
deployment, err := d.db.GetDeployment(ctx, name)
if err != nil {
return translatePGError(err)
}

err = d.db.SetDeploymentDesiredReplicas(ctx, key, int32(minReplicas))
err = d.db.SetDeploymentDesiredReplicas(ctx, name, int32(minReplicas))
if err != nil {
return translatePGError(err)
}

err = tx.InsertDeploymentUpdatedEvent(ctx, sql.InsertDeploymentUpdatedEventParams{
DeploymentName: string(key),
DeploymentName: name,
MinReplicas: int32(minReplicas),
PrevMinReplicas: deployment.MinReplicas,
})
Expand Down Expand Up @@ -681,7 +681,7 @@ func (d *DAL) ReplaceDeployment(ctx context.Context, newDeploymentName model.Dep
}

err = tx.InsertDeploymentCreatedEvent(ctx, sql.InsertDeploymentCreatedEventParams{
DeploymentName: newDeploymentName.String(),
DeploymentName: newDeploymentName,
Language: newDeployment.Language,
ModuleName: newDeployment.ModuleName,
MinReplicas: int32(minReplicas),
Expand Down Expand Up @@ -958,7 +958,7 @@ func (d *DAL) InsertCallEvent(ctx context.Context, call *CallEvent) error {
requestName = optional.Some(string(rn))
}
return translatePGError(d.db.InsertCallEvent(ctx, sql.InsertCallEventParams{
DeploymentName: call.DeploymentName.String(),
DeploymentName: call.DeploymentName,
RequestName: requestName,
TimeStamp: call.Time,
SourceModule: sourceModule,
Expand Down
14 changes: 7 additions & 7 deletions backend/controller/sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ WITH deployment_rel AS (
-- there is no corresponding deployment, then the deployment ID is -1
-- and the parent statement will fail due to a foreign key constraint.
SELECT CASE
WHEN sqlc.narg('deployment_name')::TEXT IS NULL
WHEN sqlc.narg('deployment_name')::deployment_name IS NULL
THEN NULL
ELSE COALESCE((SELECT id
FROM deployments d
WHERE d.name = sqlc.narg('deployment_name')
WHERE d.name = sqlc.narg('deployment_name')::deployment_name
LIMIT 1), -1) END AS id)
INSERT
INTO runners (key, endpoint, state, labels, deployment_id, last_seen)
Expand Down Expand Up @@ -210,7 +210,7 @@ SET state = 'reserved',
-- and the update will fail due to a FK constraint.
deployment_id = COALESCE((SELECT id
FROM deployments d
WHERE d.name = sqlc.arg('deployment_name')
WHERE d.name = sqlc.arg('deployment_name')::deployment_name
LIMIT 1), -1)
WHERE id = (SELECT id
FROM runners r
Expand Down Expand Up @@ -274,7 +274,7 @@ FROM rows;

-- name: InsertLogEvent :exec
INSERT INTO events (deployment_id, request_id, time_stamp, custom_key_1, type, payload)
VALUES ((SELECT id FROM deployments d WHERE d.name = sqlc.arg('deployment_name') LIMIT 1),
VALUES ((SELECT id FROM deployments d WHERE d.name = sqlc.arg('deployment_name')::deployment_name LIMIT 1),
(CASE
WHEN sqlc.narg('request_name')::TEXT IS NULL THEN NULL
ELSE (SELECT id FROM requests ir WHERE ir.name = sqlc.narg('request_name')::TEXT LIMIT 1)
Expand All @@ -293,7 +293,7 @@ VALUES ((SELECT id FROM deployments d WHERE d.name = sqlc.arg('deployment_name')
INSERT INTO events (deployment_id, type, custom_key_1, custom_key_2, payload)
VALUES ((SELECT id
FROM deployments
WHERE deployments.name = sqlc.arg('deployment_name')::TEXT),
WHERE deployments.name = sqlc.arg('deployment_name')::deployment_name),
'deployment_created',
sqlc.arg('language')::TEXT,
sqlc.arg('module_name')::TEXT,
Expand All @@ -306,7 +306,7 @@ VALUES ((SELECT id
INSERT INTO events (deployment_id, type, custom_key_1, custom_key_2, payload)
VALUES ((SELECT id
FROM deployments
WHERE deployments.name = sqlc.arg('deployment_name')::TEXT),
WHERE deployments.name = sqlc.arg('deployment_name')::deployment_name),
'deployment_updated',
sqlc.arg('language')::TEXT,
sqlc.arg('module_name')::TEXT,
Expand All @@ -318,7 +318,7 @@ VALUES ((SELECT id
-- name: InsertCallEvent :exec
INSERT INTO events (deployment_id, request_id, time_stamp, type,
custom_key_1, custom_key_2, custom_key_3, custom_key_4, payload)
VALUES ((SELECT id FROM deployments WHERE deployments.name = sqlc.arg('deployment_name')::TEXT),
VALUES ((SELECT id FROM deployments WHERE deployments.name = sqlc.arg('deployment_name')::deployment_name),
(CASE
WHEN sqlc.narg('request_name')::TEXT IS NULL THEN NULL
ELSE (SELECT id FROM requests ir WHERE ir.name = sqlc.narg('request_name')::TEXT)
Expand Down
23 changes: 11 additions & 12 deletions backend/controller/sql/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ddd6890

Please sign in to comment.