Skip to content

Commit

Permalink
Change to FindProvisionerResourceByTypeAndName
Browse files Browse the repository at this point in the history
  • Loading branch information
begelundmuller committed Dec 18, 2024
1 parent 2e07547 commit 6bd3032
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion admin/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ type DB interface {
DeleteProjectVariables(ctx context.Context, projectID, environment string, vars []string) error

FindProvisionerResourcesForDeployment(ctx context.Context, deploymentID string) ([]*ProvisionerResource, error)
FindProvisionerResourceByName(ctx context.Context, deploymentID, typ, name string) (*ProvisionerResource, error)
FindProvisionerResourceByTypeAndName(ctx context.Context, deploymentID, typ, name string) (*ProvisionerResource, error)
InsertProvisionerResource(ctx context.Context, opts *InsertProvisionerResourceOptions) (*ProvisionerResource, error)
UpdateProvisionerResource(ctx context.Context, id string, opts *UpdateProvisionerResourceOptions) (*ProvisionerResource, error)
DeleteProvisionerResource(ctx context.Context, id string) error
Expand Down
2 changes: 1 addition & 1 deletion admin/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -2232,7 +2232,7 @@ func (c *connection) FindProvisionerResourcesForDeployment(ctx context.Context,
return c.provisionerResourcesFromDTOs(res)
}

func (c *connection) FindProvisionerResourceByName(ctx context.Context, deploymentID, typ, name string) (*database.ProvisionerResource, error) {
func (c *connection) FindProvisionerResourceByTypeAndName(ctx context.Context, deploymentID, typ, name string) (*database.ProvisionerResource, error) {
res := &provisionerResourceDTO{}
err := c.getDB(ctx).QueryRowxContext(ctx, `SELECT * FROM provisioner_resources WHERE deployment_id = $1 AND "type" = $2 AND name = $3`, deploymentID, typ, name).StructScan(res)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion admin/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func (s *Service) provisionRuntime(ctx context.Context, opts *provisionRuntimeOp
}

func (s *Service) findProvisionedRuntimeResource(ctx context.Context, deploymentID string) (*database.ProvisionerResource, bool, error) {
pr, err := s.DB.FindProvisionerResourceByName(ctx, deploymentID, string(provisioner.ResourceTypeRuntime), "")
pr, err := s.DB.FindProvisionerResourceByTypeAndName(ctx, deploymentID, string(provisioner.ResourceTypeRuntime), "")
if err != nil {
if errors.Is(err, database.ErrNotFound) {
return nil, false, nil
Expand Down
4 changes: 2 additions & 2 deletions admin/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ProvisionOptions struct {

func (s *Service) Provision(ctx context.Context, opts *ProvisionOptions) (*database.ProvisionerResource, error) {
// Attempt to find an existing provisioned resource
pr, err := s.DB.FindProvisionerResourceByName(ctx, opts.DeploymentID, string(opts.Type), opts.Name)
pr, err := s.DB.FindProvisionerResourceByTypeAndName(ctx, opts.DeploymentID, string(opts.Type), opts.Name)
if err != nil && !errors.Is(err, database.ErrNotFound) {
return nil, err
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func (s *Service) Provision(ctx context.Context, opts *ProvisionOptions) (*datab
}

// The resource must have been created concurrently by another process, so we try to find it again.
pr, err = s.DB.FindProvisionerResourceByName(ctx, opts.DeploymentID, string(opts.Type), opts.Name)
pr, err = s.DB.FindProvisionerResourceByTypeAndName(ctx, opts.DeploymentID, string(opts.Type), opts.Name)
if err != nil {
return nil, fmt.Errorf("failed to find expected provisioner resource: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion admin/server/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *Server) Provision(ctx context.Context, req *adminv1.ProvisionRequest) (
}

// If the resource is OK, return it immediately.
res, err := s.admin.DB.FindProvisionerResourceByName(ctx, depl.ID, req.Type, req.Name)
res, err := s.admin.DB.FindProvisionerResourceByTypeAndName(ctx, depl.ID, req.Type, req.Name)
if err != nil && !errors.Is(err, database.ErrNotFound) {
return nil, err
}
Expand Down

0 comments on commit 6bd3032

Please sign in to comment.