Skip to content

fix: auto-sanitize hyphenated dolt_database on embedded-mode upgrade (post-#2142 gap) #3231

@kevglynn

Description

@kevglynn

Summary

Projects initialized before #2142 (or via --database with hyphens) retain hyphenated dolt_database names in metadata.json. When upgrading to bd 1.0.0 — which defaults to embedded mode — embedded Dolt rejects these names with an unhelpful invalid database name error. All beads become inaccessible until the user manually edits metadata.json.

This is a remaining gap from the #2142 fix, which only addressed new bd init runs.

Problem

How it happens

  1. User has project my-project initialized before bd init should sanitize hyphens to underscores in dolt_database name #2142, or used --database my-project (which passes ValidateDatabaseName since it allows hyphens)
  2. metadata.json contains "dolt_database": "my-project"
  3. User upgrades to bd 1.0.0 (embedded mode default)
  4. Every bd command fails: invalid database name: "my-project"

Gaps in current code

Component Issue
newDoltStoreFromConfig Passes hyphenated name directly to embedded engine — no sanitization
embeddeddolt error Says invalid database name with no guidance on how to fix it
bd doctor Hyphen check only runs in server mode (RunServerHealthChecks); embedded-default projects skip it entirely
ValidateDatabaseName Allows hyphens ([a-zA-Z0-9_\-]), but embedded mode rejects them — inconsistent
checkMetadataConfigValues Does not check dolt_database for embedded-incompatible characters

Impact

Any pre-#2142 project in a hyphenated directory (very common: my-project, cool-app, jtbot-core) becomes completely unusable after upgrading to embedded mode. The workaround — manually adding "dolt_mode": "server" or editing dolt_database — is undiscoverable.

Proposed Fix

1. Auto-sanitize on embedded store open (store_factory.go)

When newDoltStoreFromConfig is about to open an embedded store with a hyphenated database name:

  • Sanitize hyphens → underscores
  • Rename the existing database if it exists with the old name
  • Persist the sanitized name back to metadata.json
  • Log the migration for visibility

2. Better error in embedded mode (embeddeddolt/open.go, store.go)

If identifier validation fails and the name contains hyphens, add actionable guidance:

invalid database name "my-project": hyphens are not allowed in embedded mode.
Run 'bd doctor --fix' or replace hyphens with underscores in .beads/metadata.json dolt_database field.

3. Doctor check for embedded mode (doctor/config_values.go)

Add a dolt_database validation to checkMetadataConfigValues that flags hyphenated names when dolt_mode is not server.

4. Align --database validation with embedded mode (init.go)

When --database is provided and the build will use embedded mode, reject names that contain hyphens early (before any side effects).

Environment

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions