fix(dolt): proper server mode support for routing and storage
- FindDatabasePath now handles Dolt server mode (no local dir required) - main.go uses NewFromConfigWithOptions for Dolt to read server settings - Routing uses factory via callback to respect backend configuration - Handle Dolt "database exists" error (error 1007) gracefully Previously, Dolt server mode failed because: 1. FindDatabasePath required a local directory to exist 2. main.go bypassed server mode config when creating Dolt storage 3. Routing always opened SQLite regardless of backend config Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Steve Yegge
parent
13c362e67e
commit
e82f5136c1
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/steveyegge/beads/internal/beads"
|
||||
"github.com/steveyegge/beads/internal/debug"
|
||||
"github.com/steveyegge/beads/internal/storage/sqlite"
|
||||
"github.com/steveyegge/beads/internal/storage/factory"
|
||||
)
|
||||
|
||||
// ensureDirectMode makes sure the CLI is operating in direct-storage mode.
|
||||
@@ -52,7 +52,8 @@ func disableDaemonForFallback(reason string) {
|
||||
}
|
||||
}
|
||||
|
||||
// ensureStoreActive guarantees that a local SQLite store is initialized and tracked.
|
||||
// ensureStoreActive guarantees that a storage backend is initialized and tracked.
|
||||
// Uses the factory to respect metadata.json backend configuration (SQLite, Dolt embedded, or Dolt server).
|
||||
func ensureStoreActive() error {
|
||||
lockStore()
|
||||
active := isStoreActive() && getStore() != nil
|
||||
@@ -61,47 +62,44 @@ func ensureStoreActive() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
path := getDBPath()
|
||||
if path == "" {
|
||||
if found := beads.FindDatabasePath(); found != "" {
|
||||
setDBPath(found)
|
||||
path = found
|
||||
} else {
|
||||
// Check if this is a JSONL-only project
|
||||
beadsDir := beads.FindBeadsDir()
|
||||
if beadsDir != "" {
|
||||
jsonlPath := filepath.Join(beadsDir, "issues.jsonl")
|
||||
if _, err := os.Stat(jsonlPath); err == nil {
|
||||
// JSONL exists - check if no-db mode is configured
|
||||
if isNoDbModeConfigured(beadsDir) {
|
||||
return fmt.Errorf("this project uses JSONL-only mode (no SQLite database).\n" +
|
||||
"Hint: use 'bd --no-db <command>' or set 'no-db: true' in config.yaml")
|
||||
}
|
||||
// JSONL exists but no-db not configured - fresh clone scenario
|
||||
return fmt.Errorf("found JSONL file but no database: %s\n"+
|
||||
"Hint: run 'bd init' to create the database and import issues,\n"+
|
||||
" or use 'bd --no-db' for JSONL-only mode", jsonlPath)
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("no beads database found.\n" +
|
||||
"Hint: run 'bd init' to create a database in the current directory,\n" +
|
||||
" or use 'bd --no-db' for JSONL-only mode")
|
||||
// Find the .beads directory
|
||||
beadsDir := beads.FindBeadsDir()
|
||||
if beadsDir == "" {
|
||||
return fmt.Errorf("no beads database found.\n" +
|
||||
"Hint: run 'bd init' to create a database in the current directory,\n" +
|
||||
" or use 'bd --no-db' for JSONL-only mode")
|
||||
}
|
||||
|
||||
// Check if this is a JSONL-only project
|
||||
jsonlPath := filepath.Join(beadsDir, "issues.jsonl")
|
||||
if _, err := os.Stat(jsonlPath); err == nil {
|
||||
// JSONL exists - check if no-db mode is configured
|
||||
if isNoDbModeConfigured(beadsDir) {
|
||||
return fmt.Errorf("this project uses JSONL-only mode (no SQLite database).\n" +
|
||||
"Hint: use 'bd --no-db <command>' or set 'no-db: true' in config.yaml")
|
||||
}
|
||||
}
|
||||
|
||||
sqlStore, err := sqlite.New(getRootContext(), path)
|
||||
// Use factory to create the appropriate backend (SQLite, Dolt embedded, or Dolt server)
|
||||
// based on metadata.json configuration
|
||||
store, err := factory.NewFromConfig(getRootContext(), beadsDir)
|
||||
if err != nil {
|
||||
// Check for fresh clone scenario
|
||||
if isFreshCloneError(err) {
|
||||
beadsDir := filepath.Dir(path)
|
||||
handleFreshCloneError(err, beadsDir)
|
||||
return fmt.Errorf("database not initialized")
|
||||
// Check for fresh clone scenario (JSONL exists but no database)
|
||||
if _, statErr := os.Stat(jsonlPath); statErr == nil {
|
||||
return fmt.Errorf("found JSONL file but no database: %s\n"+
|
||||
"Hint: run 'bd init' to create the database and import issues,\n"+
|
||||
" or use 'bd --no-db' for JSONL-only mode", jsonlPath)
|
||||
}
|
||||
return fmt.Errorf("failed to open database: %w", err)
|
||||
}
|
||||
|
||||
// Update the database path for compatibility with code that expects it
|
||||
if dbPath := beads.FindDatabasePath(); dbPath != "" {
|
||||
setDBPath(dbPath)
|
||||
}
|
||||
|
||||
lockStore()
|
||||
setStore(sqlStore)
|
||||
setStore(store)
|
||||
setStoreActive(true)
|
||||
unlockStore()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user