TestCopyLiveDatabaseToFile funktioniert

This commit is contained in:
2025-07-29 09:42:53 +02:00
parent 54ddff3c11
commit 05c71ffa71
4 changed files with 79 additions and 57 deletions
+6 -2
View File
@@ -13,6 +13,7 @@ import (
"github.com/gin-gonic/gin"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
// Constants for test data management
@@ -221,8 +222,11 @@ func copyTableData(sourceDB, targetDB *gorm.DB, model interface{}) error {
break
}
// Batch in SQLite einfügen
if err := targetDB.Model(model).Create(&records).Error; err != nil {
// Batch in SQLite einfügen mit Konflikt-Behandlung
// Verwende Clauses.OnConflict um bestehende Datensätze zu ersetzen
if err := targetDB.Model(model).Clauses(clause.OnConflict{
UpdateAll: true,
}).Create(&records).Error; err != nil {
return err
}
}