fix(init): allow fresh clones with JSONL to run bd init (bd-4h9)
Previously, bd init blocked when JSONL existed with issues but no database, telling users to run 'bd doctor --fix'. But doctor --fix just ran bd migrate which requires an existing database - creating a circular dependency. Now: - bd init allows fresh clones (JSONL exists, no database) to proceed - bd init creates the database and imports from JSONL automatically - bd doctor --fix runs bd init (not migrate) when there's no database 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -4,9 +4,11 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// DatabaseVersion fixes database version mismatches by running bd migrate
|
||||
// DatabaseVersion fixes database version mismatches by running bd migrate,
|
||||
// or creates the database from JSONL by running bd init for fresh clones (bd-4h9).
|
||||
func DatabaseVersion(path string) error {
|
||||
// Validate workspace
|
||||
if err := validateBeadsWorkspace(path); err != nil {
|
||||
@@ -19,7 +21,25 @@ func DatabaseVersion(path string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Run bd migrate
|
||||
// Check if database exists - if not, run init instead of migrate (bd-4h9)
|
||||
beadsDir := filepath.Join(path, ".beads")
|
||||
dbPath := filepath.Join(beadsDir, "beads.db")
|
||||
|
||||
if _, err := os.Stat(dbPath); os.IsNotExist(err) {
|
||||
// No database - this is a fresh clone, run bd init
|
||||
fmt.Println("→ No database found, running 'bd init' to hydrate from JSONL...")
|
||||
cmd := exec.Command(bdBinary, "init") // #nosec G204 -- bdBinary from validated executable path
|
||||
cmd.Dir = path
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("failed to initialize database: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Database exists - run bd migrate
|
||||
cmd := exec.Command(bdBinary, "migrate") // #nosec G204 -- bdBinary from validated executable path
|
||||
cmd.Dir = path // Set working directory without changing process dir
|
||||
cmd.Stdout = os.Stdout
|
||||
|
||||
Reference in New Issue
Block a user