{"record":{"id":"bfc62109bb53f1e4","repo":"henrygd/beszel","slug":"failed-to-find-systems-collection-v","errorCode":null,"errorMessage":"failed to find systems collection: %v","messagePattern":"failed to find systems collection: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hub/config/config.go","lineNumber":126,"sourceCode":"\t\t\texistingSystem.Set(\"users\", sysConfig.Users)\n\t\t\texistingSystem.Set(\"port\", sysConfig.Port)\n\t\t\tif err := h.Save(existingSystem); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\t// Only update token if one is specified in config, otherwise preserve existing token\n\t\t\tif sysConfig.Token != \"\" {\n\t\t\t\tif err := updateFingerprintToken(h, existingSystem.Id, sysConfig.Token); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tdelete(existingSystemsMap, key)\n\t\t} else {\n\t\t\t// Create new system\n\t\t\tsystemsCollection, err := h.FindCollectionByNameOrId(\"systems\")\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to find systems collection: %v\", err)\n\t\t\t}\n\t\t\tnewSystem := core.NewRecord(systemsCollection)\n\t\t\tnewSystem.Set(\"name\", sysConfig.Name)\n\t\t\tnewSystem.Set(\"host\", sysConfig.Host)\n\t\t\tnewSystem.Set(\"port\", sysConfig.Port)\n\t\t\tnewSystem.Set(\"users\", sysConfig.Users)\n\t\t\tnewSystem.Set(\"info\", system.Info{})\n\t\t\tnewSystem.Set(\"status\", \"pending\")\n\t\t\tif err := h.Save(newSystem); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to create new system: %v\", err)\n\t\t\t}\n\n\t\t\t// For new systems, generate token if not provided\n\t\t\ttoken := sysConfig.Token\n\t\t\tif token == \"\" {\n\t\t\t\ttoken = uuid.New().String()\n\t\t\t}\n","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/internal/hub/config/config.go#L108-L144","documentation":"While creating systems from config.yml that don't yet exist, SyncSystems looks up the PocketBase collection named/id 'systems' via h.FindCollectionByNameOrId. This error wraps a failure of that lookup, meaning the collection is missing or the name doesn't match. SyncSystems aborts so partial syncs don't occur mid-loop.","triggerScenarios":"Calling SyncSystems on a PocketBase instance where no collection named 'systems' exists (fresh database that never ran migrations), or the collection was renamed/deleted.","commonSituations":"Deploying to a brand-new PocketBase DB without applying schema migrations; renaming the collection in the admin UI while config sync still references 'systems'; pointing the hub at the wrong PocketBase app/database.","solutions":["Run your schema migrations so the 'systems' collection is created before calling SyncSystems.","Verify the collection name in the PocketBase admin UI matches 'systems' exactly (case-sensitive).","Create the collection manually with the expected fields (name, host, port, users, info, status) if migrations are not used.","Confirm the app is connected to the intended PocketBase database file/environment."],"exampleFix":"// before: fresh DB, no migrations\nerr := app.SyncSystems() // failed to find systems collection: ...\n\n// after: ensure migrations register the collection\nfunc init() {\n    m.OnServe().BindFunc(func(e *core.ServeEvent) error {\n        ensureSystemsCollection(e.App)\n        return e.Next()\n    })\n}","handlingStrategy":"validation","validationCode":"collections, err := app.ListCollections()\nif err != nil { return err }\nfound := false\nfor _, c := range collections { if c.Name == \"systems\" { found = true } }\nif !found { return fmt.Errorf(\"run migrations first: 'systems' collection missing\") }","typeGuard":"func systemsCollectionExists(app *pocketbase.PocketBase) bool {\n    _, err := app.FindCollectionByNameOrId(\"systems\")\n    return err == nil\n}","tryCatchPattern":"if err := SyncSystems(); err != nil {\n    if strings.Contains(err.Error(), \"failed to find systems collection\") {\n        return fmt.Errorf(\"apply DB migrations to create 'systems' collection, then retry: %w\", err)\n    }\n    return err\n}","preventionTips":["Run schema migrations as part of every deployment before config sync.","Don't rename the 'systems' collection in the admin UI; treat the name as an API contract.","Add a health check that asserts required collections exist at startup.","Verify you're pointed at the intended PocketBase data directory/environment."],"tags":["pocketbase","database","migration","config"],"backgroundTag":"collection-not-found","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}