From 6f5ee013e64aa4bbe90ae5c17743263651ac2423 Mon Sep 17 00:00:00 2001 From: Fodesu <75713465+Fodesu@users.noreply.github.com> Date: Sat, 14 Feb 2026 23:40:47 +0800 Subject: [PATCH] fix(models): models id change can not be save (#49) --- db/queries/models.sql | 1 + internal/db/sqlc/models.sql.go | 15 +++++++++------ internal/models/models.go | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/db/queries/models.sql b/db/queries/models.sql index 62f8566a..3a472652 100644 --- a/db/queries/models.sql +++ b/db/queries/models.sql @@ -104,6 +104,7 @@ RETURNING *; -- name: UpdateModelByModelID :one UPDATE models SET + model_id = sqlc.arg(new_model_id), name = sqlc.arg(name), llm_provider_id = sqlc.arg(llm_provider_id), dimensions = sqlc.arg(dimensions), diff --git a/internal/db/sqlc/models.sql.go b/internal/db/sqlc/models.sql.go index 7ff72b25..fd4fd53e 100644 --- a/internal/db/sqlc/models.sql.go +++ b/internal/db/sqlc/models.sql.go @@ -673,17 +673,19 @@ func (q *Queries) UpdateModel(ctx context.Context, arg UpdateModelParams) (Model const updateModelByModelID = `-- name: UpdateModelByModelID :one UPDATE models SET - name = $1, - llm_provider_id = $2, - dimensions = $3, - is_multimodal = $4, - type = $5, + model_id = $1, + name = $2, + llm_provider_id = $3, + dimensions = $4, + is_multimodal = $5, + type = $6, updated_at = now() -WHERE model_id = $6 +WHERE model_id = $7 RETURNING id, model_id, name, llm_provider_id, dimensions, is_multimodal, type, created_at, updated_at ` type UpdateModelByModelIDParams struct { + NewModelID string `json:"new_model_id"` Name pgtype.Text `json:"name"` LlmProviderID pgtype.UUID `json:"llm_provider_id"` Dimensions pgtype.Int4 `json:"dimensions"` @@ -694,6 +696,7 @@ type UpdateModelByModelIDParams struct { func (q *Queries) UpdateModelByModelID(ctx context.Context, arg UpdateModelByModelIDParams) (Model, error) { row := q.db.QueryRow(ctx, updateModelByModelID, + arg.NewModelID, arg.Name, arg.LlmProviderID, arg.Dimensions, diff --git a/internal/models/models.go b/internal/models/models.go index cc103060..18b7fdbd 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -235,6 +235,7 @@ func (s *Service) UpdateByModelID(ctx context.Context, modelID string, req Updat params := sqlc.UpdateModelByModelIDParams{ ModelID: modelID, + NewModelID: model.ModelID, IsMultimodal: model.IsMultimodal, Type: string(model.Type), }