mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-21 03:56:07 +00:00
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.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user