mirror of
https://github.com/holos-run/holos.git
synced 2026-03-19 08:44:58 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
327193215b | ||
|
|
b98b5cae3f |
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -1 +1 @@
|
||||
0
|
||||
1
|
||||
|
||||
Reference in New Issue
Block a user