From c20b9143db8d44751e0ee4e41bc94a8d9f32a501 Mon Sep 17 00:00:00 2001 From: SoXX Date: Wed, 3 Jul 2024 09:52:39 +0200 Subject: [PATCH] fix: do nothing by duplicate key Signed-off-by: SoXX --- internal/postgres/tag.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/postgres/tag.go b/internal/postgres/tag.go index bc7bef6..e22426b 100644 --- a/internal/postgres/tag.go +++ b/internal/postgres/tag.go @@ -3,6 +3,7 @@ package postgres import ( "context" "errors" + "gorm.io/gorm/clause" otterError "git.dragse.it/anthrove/otter-space-sdk/v2/pkg/error" @@ -220,7 +221,10 @@ func CreateTagAliasInBatch(ctx context.Context, db *gorm.DB, tagAliases []models return &otterError.EntityValidationFailed{Reason: "batch size cannot be zero"} } - result := db.WithContext(ctx).CreateInBatches(tagAliases, batchSize) + result := db.WithContext(ctx).Clauses(clause.OnConflict{ + Columns: []clause.Column{{Name: "name"}}, + DoNothing: true, + }).CreateInBatches(tagAliases, batchSize) if result.Error != nil { if errors.Is(result.Error, gorm.ErrDuplicatedKey) { return &otterError.EntityAlreadyExists{}