fix: use prefix-based Dolt database names to prevent cross-rig contamination (bd-u8rda)

When multiple rigs share the same Dolt server, they now get separate databases
named beads_<prefix> (e.g. beads_gt, beads_bd) instead of all sharing "beads".

- migrate_dolt.go: derive database name from issue prefix during migration
- init.go: set DoltDatabase in metadata.json based on prefix during init
- store.go: backtick-quote database name in CREATE DATABASE for safety

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/polecats/obsidian
Rig: beads
Role: polecats
This commit is contained in:
obsidian 2026-02-06 21:15:17 -08:00 • committed by gastown/crew/jack
commit 249609de0c
3 changed files with 21 additions and 3 deletions

View file

@ -345,7 +345,12 @@ variable.`,
if backend == configfile.BackendDolt {
// Dolt uses a directory, not a file
storagePath = filepath.Join(beadsDir, "dolt")
store, err = factory.New(ctx, backend, storagePath)
// Use prefix-based database name to avoid cross-rig contamination (bd-u8rda)
dbName := "beads"
if prefix != "" {
dbName = "beads_" + prefix
}
store, err = factory.NewWithOptions(ctx, backend, storagePath, factory.Options{Database: dbName})
} else {
storagePath = initDBPath
store, err = sqlite.New(ctx, storagePath)
@ -443,6 +448,12 @@ variable.`,
cfg.Database = "dolt"
}
// Set prefix-based SQL database name to avoid cross-rig contamination (bd-u8rda).
// E.g., prefix "gt" → database "beads_gt", prefix "bd" → database "beads_bd".
if prefix != "" {
cfg.DoltDatabase = "beads_" + prefix
}
// Save server mode configuration (bd-dolt.2.2)
if serverMode {
cfg.DoltMode = configfile.DoltModeServer

View file

@ -110,7 +110,13 @@ func handleToDoltMigration(dryRun bool, autoYes bool) {
// Create Dolt database
printProgress("Creating Dolt database...")
doltStore, err := dolt.New(ctx, &dolt.Config{Path: doltPath})
// Use prefix-based database name to avoid cross-rig contamination (bd-u8rda).
// E.g., prefix "gt" → database "beads_gt", prefix "bd" → database "beads_bd".
dbName := "beads"
if data.prefix != "" {
dbName = "beads_" + data.prefix
}
doltStore, err := dolt.New(ctx, &dolt.Config{Path: doltPath, Database: dbName})
if err != nil {
exitWithError("dolt_create_failed", err.Error(), "")
}
@ -137,6 +143,7 @@ func handleToDoltMigration(dryRun bool, autoYes bool) {
// Update metadata.json
cfg.Backend = configfile.BackendDolt
cfg.Database = "dolt"
cfg.DoltDatabase = dbName
cfg.DoltServerPort = configfile.DefaultDoltServerPort
if err := cfg.Save(beadsDir); err != nil {
exitWithError("config_save_failed", err.Error(),

View file

@ -243,7 +243,7 @@ func openServerConnection(ctx context.Context, cfg *Config) (*sql.DB, string, er
}
defer func() { _ = initDB.Close() }()
_, err = initDB.ExecContext(ctx, fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s", cfg.Database))
_, err = initDB.ExecContext(ctx, fmt.Sprintf("CREATE DATABASE IF NOT EXISTS `%s`", cfg.Database))
if err != nil {
// Dolt may return error 1007 even with IF NOT EXISTS - ignore if database already exists
errLower := strings.ToLower(err.Error())