mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 21:49:15 +00:00
Improve codeql action + fix test db clean
This commit is contained in:
@@ -190,21 +190,17 @@ func MigrateDatabase(db *gorm.DB) error {
|
||||
|
||||
func ClearDatabase(db *gorm.DB) error {
|
||||
err := db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Exec("SET FOREIGN_KEY_CHECKS = 0;").Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sess := tx.Session(&gorm.Session{AllowGlobalUpdate: true})
|
||||
dry_run := tx.Session(&gorm.Session{DryRun: true})
|
||||
for _, model := range database_models {
|
||||
if err := sess.Delete(model).Error; err != nil {
|
||||
// get table name of model structure
|
||||
table := dry_run.Find(model).Statement.Table
|
||||
|
||||
if err := tx.Exec(fmt.Sprintf("TRUNCATE TABLE %s", table)).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := tx.Exec("SET FOREIGN_KEY_CHECKS = 1;").Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user