Compare commits

..

2 Commits

Author SHA1 Message Date
Jeff McCune
327193215b version: 0.89.1 2024-07-18 14:42:24 -07:00
Jeff McCune
b98b5cae3f PlatformService: do nothing when platform already exists
Previously the CreatePlatform rpc wrote over all fields when the
platform already exists.  This is surprising and basically the
UpdatePlatform rpc.

This patch changes the behavior to do nothing except set the
already_exists flag in the response message.

Users who have the use case of needing to know if the creation actually
created a new resource should use the API to check the already_exists
flag.  The CLI has no affordance for this other than parsing the log
messages.
2024-07-18 14:27:03 -07:00
3 changed files with 16 additions and 14 deletions

View File

@@ -1,6 +1,8 @@
package create
import (
"fmt"
"github.com/holos-run/holos/internal/cli/command"
"github.com/holos-run/holos/internal/cli/secret"
"github.com/holos-run/holos/internal/client"
@@ -46,14 +48,14 @@ func NewPlatform(cfg *client.Config) *cobra.Command {
return err
}
log := logger.FromContext(ctx)
verb := "created"
action := "created"
if resp.GetAlreadyExists() {
verb = "updated"
action = "already exists"
}
pf := resp.GetPlatform()
name := pf.GetName()
log.InfoContext(ctx, verb+" platform "+name, "name", name, "id", pf.GetId(), "org", pf.GetOwner().GetOrgId(), "exists", resp.GetAlreadyExists())
log.InfoContext(ctx, fmt.Sprintf("platform %s %s", name, action), "name", name, "id", pf.GetId(), "org", pf.GetOwner().GetOrgId(), "exists", resp.GetAlreadyExists())
return nil
}

View File

@@ -44,9 +44,14 @@ func (h *PlatformHandler) CreatePlatform(ctx context.Context, req *connect.Reque
m := req.Msg.GetCreate()
tryCreateID, err := uuid.NewV7()
if err != nil {
return nil, connect.NewError(connect.CodeInternal, errors.Wrap(err))
}
now := time.Now()
platformID, err := h.db.Platform.Create().
SetID(tryCreateID).
SetOrgID(dbOrg.ID).
SetCreatorID(dbUser.ID).
SetCreatedAt(now).
@@ -58,12 +63,7 @@ func (h *PlatformHandler) CreatePlatform(ctx context.Context, req *connect.Reque
SetModel(&storage.Model{Model: m.GetModel()}).
OnConflict(
sql.ConflictColumns(entplatform.FieldOrgID, entplatform.FieldName),
sql.ResolveWithNewValues(),
sql.ResolveWith(func(u *sql.UpdateSet) {
u.SetIgnore(entplatform.FieldID)
u.SetIgnore(entplatform.FieldCreatedByID)
u.SetIgnore(entplatform.FieldCreatedAt)
}),
sql.ResolveWithIgnore(),
).
ID(ctx)
if err != nil {
@@ -76,15 +76,15 @@ func (h *PlatformHandler) CreatePlatform(ctx context.Context, req *connect.Reque
}
var already_exists bool
verb := "created"
action := "created"
if entPlatform.CreatedAt != entPlatform.UpdatedAt {
if tryCreateID != platformID {
already_exists = true
verb = "updated"
action = "already exists"
}
log := logger.FromContext(ctx)
log.InfoContext(ctx, fmt.Sprintf("%s platform %s in org %s", verb, platformID, dbOrg.ID))
log.InfoContext(ctx, fmt.Sprintf("platform %s %s in org %s", entPlatform.Name, action, dbOrg.ID))
resp := &platform.CreatePlatformResponse{
Platform: PlatformToRPC(entPlatform),

View File

@@ -1 +1 @@
0
1