fix(init): sanitize dots in metadata.json DoltDatabase and add early validation (#3128)#3129
Merged
maphew merged 3 commits intogastownhall:mainfrom Apr 10, 2026
Merged
Conversation
…validation
Two bugs in bd init when the directory name contains characters that are
invalid or non-standard in Dolt/MySQL identifiers:
1. metadata.json mismatch: dbName sanitized hyphens AND dots to underscores
(lines 430-431), but cfg.DoltDatabase only sanitized hyphens (line 666).
This caused bd init in e.g. GPUPolynomials.jl to create a database named
GPUPolynomials_jl but record dolt_database: "GPUPolynomials.jl" in
metadata.json, breaking every subsequent command with a cryptic
"invalid database name" error.
Fix: add dot replacement to cfg.DoltDatabase to match dbName sanitization.
2. No early validation for characters that survive sanitization (spaces, @,
etc.): errors came from deep in the storage layer with no actionable hint.
Fix: validate dbName with dolt.ValidateDatabaseName after it is computed;
if invalid, fail immediately with a clear message:
Error: directory name "my project" produces an invalid database name "my project".
Re-run with a valid prefix: bd init --prefix <name>
Fixes gastownhall#3128
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ation - prefix_dot_sanitized: verifies that --prefix GPUPolynomials.jl writes DoltDatabase "GPUPolynomials_jl" to metadata.json (not "GPUPolynomials.jl") - invalid_dirname_errors_early: verifies that a directory whose name contains a space exits non-zero with an actionable error message Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Verifies that bd init in a directory named like MyPkg.jl (no --prefix) auto-detects the name, sanitizes the dot in metadata.json DoltDatabase, and that bd list succeeds immediately after — confirming the stored name matches the actual Dolt database. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Collaborator
|
Thanks @jjgarzella — great first PR to beads! 🎉 Clean fix, solid tests, and the error message for unsanitizable directory names is a really nice touch. Welcome aboard! |
5 tasks
maphew
pushed a commit
that referenced
this pull request
Apr 20, 2026
…3231) (#3232) Auto-sanitize hyphenated `dolt_database` names on embedded-mode upgrade. Projects initialized before #2142 retain hyphenated names in `metadata.json`; after the 1.0.0 embedded-mode default flip, those names are rejected by the embedded Dolt engine. This change detects legacy names on store open, renames the database directory, persists the fix to `metadata.json`, and adds a doctor check + init guard for future prevention. Closes #3231. Related: #2142, #2160, #3128, #3129. Thanks @kevglynn for the thorough fix, migration safety (collision detection, crash-safe ordering), and test coverage.
mzlee
pushed a commit
to mzlee/beads
that referenced
this pull request
Apr 22, 2026
…astownhall#3231) (gastownhall#3232) Auto-sanitize hyphenated `dolt_database` names on embedded-mode upgrade. Projects initialized before gastownhall#2142 retain hyphenated names in `metadata.json`; after the 1.0.0 embedded-mode default flip, those names are rejected by the embedded Dolt engine. This change detects legacy names on store open, renames the database directory, persists the fix to `metadata.json`, and adds a doctor check + init guard for future prevention. Closes gastownhall#3231. Related: gastownhall#2142, gastownhall#2160, gastownhall#3128, gastownhall#3129. Thanks @kevglynn for the thorough fix, migration safety (collision detection, crash-safe ordering), and test coverage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3128 —
bd initin a directory with dots in its name (e.g.GPUPolynomials.jl, common in Julia development) silently produced a broken installation: the database was created under one name butmetadata.jsonrecorded a different name, causing every subsequentbdcommand to fail with a crypticinvalid database nameerror.Root Cause
Two bugs in
cmd/bd/init.go:Bug 1 — metadata.json mismatch:
dbNamesanitized both hyphens and dots → underscores (lines 430–431), butcfg.DoltDatabase(written tometadata.json) only sanitized hyphens (line 666). The comment above line 430 explicitly warns these must match — they didn't.Bug 2 — unclear error for unsanitizable characters:
Characters like spaces,
@,!that survive all sanitization caused an error deep inside the storage layer with no actionable guidance.Changes
cmd/bd/init.goline 666: add dot → underscore replacement tocfg.DoltDatabaseto matchdbNamesanitizationcmd/bd/init.goafter line 440: add earlydolt.ValidateDatabaseNamecheck with clear error message and--prefixhint when the auto-derived name is invalidBefore / After
Before:
After (dots — silently fixed):
After (unsanitizable chars — clear error):
Test Plan
bd initin a*.jldirectory succeeds andbd listworks aftermetadata.jsondolt_databasefield contains no dots after init in dotted directorybd initin a directory with a space fails immediately with message containing--prefix--databaseflag validation path unaffectedbd init --prefix mynamein any directory still works as beforeNote: this is JJ's first time making a PR to beads with an AI agent, so if anything is wrong, we would appreciate feedback!
🤖 Generated with Claude Code