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{}