Files
3x-ui/internal/database/migration_models_test.go
T
MHSanaei 54fc0fd47c fix(database): make cross-db migration lossless, transactional, and pre-checked
migrationModels was missing ClientGroup and ClientGlobalTraffic, so both
migration directions silently dropped client groups and global client
traffic; the model list is now extracted to allModels and a parity test
keeps the two lists from drifting again. MigrateData runs its truncate
and copy inside one transaction so a failed import rolls back instead of
leaving the destination truncated (sequences resync after commit since
setval is non-transactional). New PrepareSQLiteForMigration rejects
uploads that are not a panel database and AutoMigrates old backups so
their missing tables cannot break the row copy.
2026-07-12 20:14:07 +02:00

30 lines
725 B
Go

package database
import (
"reflect"
"testing"
)
func TestMigrationModelsMatchPanelModels(t *testing.T) {
names := func(models []any) map[string]bool {
set := make(map[string]bool, len(models))
for _, m := range models {
set[reflect.TypeOf(m).Elem().Name()] = true
}
return set
}
panel := names(allModels())
migration := names(migrationModels())
for name := range panel {
if !migration[name] {
t.Errorf("model %s is in allModels but missing from migrationModels: cross-db migration silently drops its rows", name)
}
}
for name := range migration {
if !panel[name] {
t.Errorf("model %s is in migrationModels but missing from allModels: its table never exists on a live panel", name)
}
}
}