develop/batch-jobs #13
@ -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{}
|
||||
|
Reference in New Issue
Block a user