From 072d2eeae0338a58906b2f3ea216ddff0a4019c4 Mon Sep 17 00:00:00 2001 From: Kenneth Date: Mon, 2 Dec 2024 23:59:04 +0000 Subject: [PATCH] fix: sql conflict when image tag reused --- internal/template/template_manager.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/template/template_manager.go b/internal/template/template_manager.go index fcc348c..3f97517 100644 --- a/internal/template/template_manager.go +++ b/internal/template/template_manager.go @@ -288,6 +288,7 @@ func (mgr *templateManager) buildTemplate(ctx context.Context, template *templat outputChan <- stream } else if errmsg, ok := msg["error"].(string); ok { outputChan <- errmsg + "\n" + return } else if status, ok := msg["status"].(string); ok { var text string if progress, ok := msg["progress"].(string); ok { @@ -312,10 +313,14 @@ func (mgr *templateManager) buildTemplate(ctx context.Context, template *templat ImageID: imageID, } - _, err = tx.NewInsert().Model(img).Exec(ctx) + _, err = tx.NewInsert().Model(img). + On("CONFLICT DO UPDATE"). + Set("image_id = EXCLUDED.image_id"). + Exec(ctx) if err != nil { _ = tx.Rollback() outputChan <- err + return } } @@ -323,6 +328,7 @@ func (mgr *templateManager) buildTemplate(ctx context.Context, template *templat if err = tx.Commit(); err != nil { _ = tx.Rollback() outputChan <- err + return } }