feat(migration): tracer

This commit is contained in:
Fu Diwei
2025-05-26 21:49:37 +08:00
parent 3bb88d9f93
commit bf1d03a30e
15 changed files with 518 additions and 355 deletions

View File

@@ -9,9 +9,17 @@ import (
func init() {
m.Register(func(app core.App) error {
tracer := NewTracer("(v0.3)1748178000")
tracer.Printf("go ...")
// migrate data
{
accesses, err := app.FindAllRecords("access")
collection, err := app.FindCollectionByNameOrId("4yzbv8urny5ja1e")
if err != nil {
return err
}
records, err := app.FindAllRecords(collection)
if err != nil {
return err
}
@@ -29,30 +37,34 @@ func init() {
"ratpanel",
"safeline",
}
for _, access := range accesses {
for _, record := range records {
changed := false
if slices.Contains(providersToUpdate, access.GetString("provider")) {
if slices.Contains(providersToUpdate, record.GetString("provider")) {
config := make(map[string]any)
if err := access.UnmarshalJSONField("config", &config); err != nil {
if err := record.UnmarshalJSONField("config", &config); err != nil {
return err
}
config["serverUrl"] = config["apiUrl"]
delete(config, "apiUrl")
access.Set("config", config)
changed = true
if config["apiUrl"] != nil {
config["serverUrl"] = config["apiUrl"]
delete(config, "apiUrl")
record.Set("config", config)
changed = true
}
}
if changed {
err = app.Save(access)
if err != nil {
if err := app.Save(record); err != nil {
return err
}
tracer.Printf("record #%s in collection '%s' updated", record.Id, collection.Name)
}
}
}
tracer.Printf("done")
return nil
}, func(app core.App) error {
return nil