mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-14 00:26:06 +00:00
54fc0fd47c
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.
30 lines
725 B
Go
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)
|
|
}
|
|
}
|
|
}
|