[management] during JSON migration filter duplicates on conflict (#4303)

This commit is contained in:
Pascal Fischer
2025-08-07 14:12:07 +02:00
committed by GitHub
parent 6da3943559
commit 9e95841252

View File

@@ -15,6 +15,7 @@ import (
log "github.com/sirupsen/logrus"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
func GetColumnName(db *gorm.DB, column string) string {
@@ -466,7 +467,7 @@ func MigrateJsonToTable[T any](ctx context.Context, db *gorm.DB, columnName stri
}
for _, value := range data {
if err := tx.Create(
if err := tx.Clauses(clause.OnConflict{DoNothing: true}).Create(
mapperFunc(row["account_id"].(string), row["id"].(string), value),
).Error; err != nil {
return fmt.Errorf("failed to insert id %v: %w", row["id"], err)