Passport/pkg/internal/services/cleaner.go

22 lines
587 B
Go
Raw Normal View History

2024-04-05 17:07:36 +00:00
package services
import (
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
2024-04-05 17:07:36 +00:00
"github.com/rs/zerolog/log"
)
func DoAutoDatabaseCleanup() {
2024-07-12 03:25:41 +00:00
log.Debug().Msg("Now cleaning up entire database...")
2024-04-05 17:07:36 +00:00
var count int64
for _, model := range database.AutoMaintainRange {
2024-07-12 03:25:41 +00:00
tx := database.C.Unscoped().Delete(model, "deleted_at IS NOT NULL")
2024-04-05 17:07:36 +00:00
if tx.Error != nil {
2024-07-12 03:25:41 +00:00
log.Error().Err(tx.Error).Msg("An error occurred when running cleaning up entire database...")
2024-04-05 17:07:36 +00:00
}
count += tx.RowsAffected
}
log.Debug().Int64("affected", count).Msg("Clean up entire database accomplished.")
}