Files
beads/internal/storage/factory/factory_dolt.go
emma 484cd9d5fd feat(dolt): add server mode config to metadata.json schema (bd-dolt.2.2)
Add Dolt server mode configuration to metadata.json for multi-writer access:

- Add DoltMode, DoltServerHost, DoltServerPort, DoltServerUser fields to Config
- Add helper methods with sensible defaults (127.0.0.1:3306, root user)
- Update factory to read server mode config and pass to dolt.Config
- Add --server, --server-host, --server-port, --server-user flags to bd init
- Validate that --server requires --backend dolt
- Add comprehensive tests for server mode configuration

Example metadata.json for server mode:
{
  "backend": "dolt",
  "database": "dolt",
  "dolt_mode": "server",
  "dolt_server_host": "192.168.1.100",
  "dolt_server_port": 3306,
  "dolt_server_user": "beads"
}

Password should be set via BEADS_DOLT_PASSWORD env var for security.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 20:01:46 -08:00

54 lines
1.5 KiB
Go

//go:build cgo
package factory
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/steveyegge/beads/internal/configfile"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/dolt"
)
func init() {
RegisterBackend(configfile.BackendDolt, func(ctx context.Context, path string, opts Options) (storage.Storage, error) {
// Check if bootstrap is needed (JSONL exists but Dolt doesn't)
// Path is the dolt subdirectory, parent is .beads directory
beadsDir := filepath.Dir(path)
bootstrapped, result, err := dolt.Bootstrap(ctx, dolt.BootstrapConfig{
BeadsDir: beadsDir,
DoltPath: path,
LockTimeout: opts.LockTimeout,
})
if err != nil {
return nil, fmt.Errorf("bootstrap failed: %w", err)
}
if bootstrapped && result != nil {
// Report bootstrap results
fmt.Fprintf(os.Stderr, "Bootstrapping Dolt from JSONL...\n")
if len(result.ParseErrors) > 0 {
fmt.Fprintf(os.Stderr, " Skipped %d malformed lines (see above for details)\n", len(result.ParseErrors))
}
fmt.Fprintf(os.Stderr, " Imported %d issues", result.IssuesImported)
if result.IssuesSkipped > 0 {
fmt.Fprintf(os.Stderr, ", skipped %d duplicates", result.IssuesSkipped)
}
fmt.Fprintf(os.Stderr, "\n Dolt database ready\n")
}
return dolt.New(ctx, &dolt.Config{
Path: path,
ReadOnly: opts.ReadOnly,
ServerMode: opts.ServerMode,
ServerHost: opts.ServerHost,
ServerPort: opts.ServerPort,
ServerUser: opts.ServerUser,
})
})
}