From 0217f7cc4ea9b5fd2dbc6f040147c4a81e8e027d Mon Sep 17 00:00:00 2001 From: LordMathis Date: Sat, 6 Dec 2025 20:58:17 +0100 Subject: [PATCH] Fix instance creation to retrieve and set the auto-generated ID --- pkg/database/instances.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/database/instances.go b/pkg/database/instances.go index 1dbdb32..ab1ec4c 100644 --- a/pkg/database/instances.go +++ b/pkg/database/instances.go @@ -45,7 +45,7 @@ func (db *sqliteDB) Create(ctx context.Context, inst *instance.Instance) error { ) VALUES (?, ?, ?, ?, ?, ?) ` - _, err = db.DB.ExecContext(ctx, query, + result, err := db.DB.ExecContext(ctx, query, row.Name, row.Status, row.CreatedAt, row.UpdatedAt, row.OptionsJSON, row.OwnerUserID, ) @@ -53,6 +53,14 @@ func (db *sqliteDB) Create(ctx context.Context, inst *instance.Instance) error { return fmt.Errorf("failed to insert instance: %w", err) } + // Get the auto-generated ID and set it on the instance + id, err := result.LastInsertId() + if err != nil { + return fmt.Errorf("failed to get last insert ID: %w", err) + } + + inst.ID = int(id) + return nil }