Skip to content

Commit

Permalink
fix: add query for getting deployments with replicas
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman committed Apr 9, 2024
1 parent 5bf4296 commit 2ff2ce2
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/controller/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (*ConsoleService) Ping(context.Context, *connect.Request[ftlv1.PingRequest]
}

func (c *ConsoleService) GetModules(ctx context.Context, req *connect.Request[pbconsole.GetModulesRequest]) (*connect.Response[pbconsole.GetModulesResponse], error) {
deployments, err := c.dal.GetActiveDeployments(ctx)
deployments, err := c.dal.GetDeploymentsWithMinReplicas(ctx)
if err != nil {
return nil, err
}
Expand Down
20 changes: 20 additions & 0 deletions backend/controller/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,26 @@ func (d *DAL) GetActiveDeployments(ctx context.Context) ([]Deployment, error) {
})
}

func (d *DAL) GetDeploymentsWithMinReplicas(ctx context.Context) ([]Deployment, error) {
rows, err := d.db.GetDeploymentsWithMinReplicas(ctx)
if err != nil {
if isNotFound(err) {
return nil, nil
}
return nil, translatePGError(err)
}
return slices.MapErr(rows, func(in sql.GetDeploymentsWithMinReplicasRow) (Deployment, error) {
return Deployment{
Key: in.Deployment.Key,
Module: in.ModuleName,
Language: in.Language,
MinReplicas: int(in.Deployment.MinReplicas),
Schema: in.Deployment.Schema,
CreatedAt: in.Deployment.CreatedAt,
}, nil
})
}

func (d *DAL) GetActiveDeploymentSchemas(ctx context.Context) ([]*schema.Module, error) {
rows, err := d.db.GetActiveDeploymentSchemas(ctx)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions backend/controller/sql/models.go

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

1 change: 1 addition & 0 deletions backend/controller/sql/querier.go

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

7 changes: 7 additions & 0 deletions backend/controller/sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ WHERE min_replicas > 0 AND r.state = 'assigned'
GROUP BY d.id, m.name, m.language
HAVING COUNT(r.id) > 0;

-- name: GetDeploymentsWithMinReplicas :many
SELECT sqlc.embed(d), m.name AS module_name, m.language
FROM deployments d
INNER JOIN modules m on d.module_id = m.id
WHERE min_replicas > 0
ORDER BY d.key;

-- name: GetActiveDeploymentSchemas :many
SELECT key, schema FROM deployments WHERE min_replicas > 0;

Expand Down
44 changes: 44 additions & 0 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 2ff2ce2

Please sign in to comment.