{"record":{"id":"5453ecd80c46ab9f","repo":"gastownhall/beads","slug":"multiple-database-files-found-in-s-v-please-man","errorCode":null,"errorMessage":"multiple database files found in %s: %v\nPlease manually rename the correct database to %s and remove others","messagePattern":"multiple database files found in (.+?): (.+?)\nPlease manually rename the correct database to (.+?) and remove others","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/init.go","lineNumber":2396,"sourceCode":"\t}\n\n\t// Filter out the target file name and any backup files\n\tvar oldDBs []string\n\tfor _, match := range matches {\n\t\tbaseName := filepath.Base(match)\n\t\tif baseName != targetName && !strings.HasSuffix(baseName, \".backup.db\") {\n\t\t\toldDBs = append(oldDBs, match)\n\t\t}\n\t}\n\n\tif len(oldDBs) == 0 {\n\t\t// No old databases to migrate\n\t\treturn nil\n\t}\n\n\tif len(oldDBs) > 1 {\n\t\t// Multiple databases found - ambiguous, require manual intervention\n\t\treturn fmt.Errorf(\"multiple database files found in %s: %v\\nPlease manually rename the correct database to %s and remove others\",\n\t\t\ttargetDir, oldDBs, targetName)\n\t}\n\n\t// Migrate the single old database\n\toldDB := oldDBs[0]\n\tif !quiet {\n\t\tfmt.Fprintf(os.Stderr, \"→ Migrating database: %s → %s\\n\", filepath.Base(oldDB), targetName)\n\t}\n\n\t// Rename the old database to the new canonical name\n\tif err := os.Rename(oldDB, targetPath); err != nil {\n\t\treturn fmt.Errorf(\"failed to migrate database %s to %s: %w\", oldDB, targetPath, err)\n\t}\n\n\tif !quiet {\n\t\tfmt.Fprintf(os.Stderr, \"✓ Database migration complete\\n\\n\")\n\t}\n","sourceCodeStart":2378,"sourceCodeEnd":2414,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/init.go#L2378-L2414","documentation":"When bd init finds more than one non-target, non-backup *.db file in .beads, it cannot tell which legacy database is the real one, so it deliberately fails closed with a message listing the files and asking the user to pick. This is an intentional ambiguity guard, not an I/O failure: renaming the wrong file would silently orphan real issue data.","triggerScenarios":"Running `bd init` when migrateOldDatabases finds len(oldDBs) > 1 — i.e. the .beads directory contains two or more *.db files other than the target name and files ending in .backup.db (e.g. beads.db.old plus issues.db).","commonSituations":"Upgrading a workspace that accumulated multiple legacy database names across bd version changes; copying databases around during a manual recovery; leftover files from interrupted earlier migrations; restoring from backup alongside the original.","solutions":["List the .beads directory, identify the newest/correct database (check mtimes and contents with a Dolt/SQLite viewer), rename it to beads.db (or the configured target name), and remove or rename the others to *.backup.db.","Move all but the correct file out of .beads temporarily, run bd init to migrate the remaining one, then reconcile extras manually.","If unsure which file is authoritative, use file sizes and modification times, or consult bd issue exports (.beads/issues.jsonl) to match the most recent state."],"exampleFix":"// before\n$ ls .beads\nissues.db  beads-old.db\n$ bd init\n# multiple database files found in .beads: [issues.db beads-old.db] ...\n\n// after: pick the correct one, archive the rest\n$ mv .beads/beads-old.db .beads/beads-old.backup.db\n$ bd init  # migrates issues.db -> beads.db (or rename manually: mv .beads/issues.db .beads/beads.db)","handlingStrategy":"validation","validationCode":"// Preflight: detect ambiguous legacy DBs before init\nmatches, _ := filepath.Glob(filepath.Join(beadsDir, \"*.db\"))\nvar ambiguous []string\nfor _, m := range matches {\n    b := filepath.Base(m)\n    if b != \"beads.db\" && !strings.HasSuffix(b, \".backup.db\") {\n        ambiguous = append(ambiguous, b)\n    }\n}\nif len(ambiguous) > 1 {\n    return fmt.Errorf(\"resolve multiple legacy DBs manually: %v\", ambiguous)\n}","typeGuard":null,"tryCatchPattern":"if err := migrateOldDatabases(targetPath, quiet); err != nil && strings.HasPrefix(err.Error(), \"multiple database files found\") {\n    // prompt the operator to choose the authoritative DB; do not auto-pick\n    return err\n}","preventionTips":["Keep exactly one active *.db in .beads; archive old ones as *.backup.db so the migrator ignores them.","After restoring from backups, remove or rename duplicates before running bd init.","Compare file mtimes/sizes to pick the authoritative database when cleaning up.","Never copy a second legacy database into .beads during manual recovery."],"tags":["migration","ambiguity","init","data-safety"],"backgroundTag":"ambiguous-database-migration","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}