Enforce canonical database naming (beads.db) - bd-165
- Added CanonicalDatabaseName constant (beads.db) and LegacyDatabaseNames list - Updated bd init to use canonical name via constant - Added daemon validation to reject non-canonical database names - Updated bd migrate to use canonical name constant - Enhanced FindDatabasePath to warn when using legacy database names - All database discovery now prefers beads.db with backward compatibility Closes bd-165
This commit is contained in:
71
beads.go
71
beads.go
@@ -19,6 +19,12 @@ import (
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
// CanonicalDatabaseName is the required database filename for all beads repositories
|
||||
const CanonicalDatabaseName = "beads.db"
|
||||
|
||||
// LegacyDatabaseNames are old names that should be migrated
|
||||
var LegacyDatabaseNames = []string{"bd.db", "issues.db", "bugs.db"}
|
||||
|
||||
// Issue represents a tracked work item with metadata, dependencies, and status.
|
||||
type (
|
||||
Issue = types.Issue
|
||||
@@ -184,38 +190,53 @@ func findDatabaseInTree() string {
|
||||
}
|
||||
|
||||
// Fall back to canonical beads.db for backward compatibility
|
||||
canonicalDB := filepath.Join(beadsDir, "beads.db")
|
||||
canonicalDB := filepath.Join(beadsDir, CanonicalDatabaseName)
|
||||
if _, err := os.Stat(canonicalDB); err == nil {
|
||||
return canonicalDB
|
||||
return canonicalDB
|
||||
}
|
||||
|
||||
// Found .beads/ directory, look for *.db files
|
||||
matches, err := filepath.Glob(filepath.Join(beadsDir, "*.db"))
|
||||
if err == nil && len(matches) > 0 {
|
||||
// Filter out backup files
|
||||
var validDBs []string
|
||||
for _, match := range matches {
|
||||
baseName := filepath.Base(match)
|
||||
// Skip backup files (e.g., beads.db.backup, bd.db.backup)
|
||||
if filepath.Ext(baseName) != ".backup" {
|
||||
validDBs = append(validDBs, match)
|
||||
}
|
||||
}
|
||||
|
||||
if len(validDBs) > 1 {
|
||||
// Multiple databases found - this is ambiguous
|
||||
// Print error to stderr but return the first one for backward compatibility
|
||||
fmt.Fprintf(os.Stderr, "Warning: Multiple database files found in %s:\n", beadsDir)
|
||||
for _, db := range validDBs {
|
||||
fmt.Fprintf(os.Stderr, " - %s\n", filepath.Base(db))
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Run 'bd init' to migrate to beads.db or manually remove old databases.\n\n")
|
||||
}
|
||||
|
||||
if len(validDBs) > 0 {
|
||||
return validDBs[0]
|
||||
}
|
||||
// Filter out backup files
|
||||
var validDBs []string
|
||||
for _, match := range matches {
|
||||
baseName := filepath.Base(match)
|
||||
// Skip backup files (e.g., beads.db.backup, bd.db.backup)
|
||||
if filepath.Ext(baseName) != ".backup" {
|
||||
validDBs = append(validDBs, match)
|
||||
}
|
||||
}
|
||||
|
||||
if len(validDBs) > 1 {
|
||||
// Multiple databases found - this is ambiguous
|
||||
// Print error to stderr but return the first one for backward compatibility
|
||||
fmt.Fprintf(os.Stderr, "Warning: Multiple database files found in %s:\n", beadsDir)
|
||||
for _, db := range validDBs {
|
||||
fmt.Fprintf(os.Stderr, " - %s\n", filepath.Base(db))
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Run 'bd init' to migrate to %s or manually remove old databases.\n\n", CanonicalDatabaseName)
|
||||
}
|
||||
|
||||
if len(validDBs) > 0 {
|
||||
// Check if using legacy name and warn
|
||||
dbName := filepath.Base(validDBs[0])
|
||||
if dbName != CanonicalDatabaseName {
|
||||
isLegacy := false
|
||||
for _, legacy := range LegacyDatabaseNames {
|
||||
if dbName == legacy {
|
||||
isLegacy = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if isLegacy {
|
||||
fmt.Fprintf(os.Stderr, "WARNING: Using legacy database name: %s\n", dbName)
|
||||
fmt.Fprintf(os.Stderr, "Run 'bd migrate' to upgrade to canonical name: %s\n\n", CanonicalDatabaseName)
|
||||
}
|
||||
}
|
||||
return validDBs[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Move up one directory
|
||||
|
||||
Reference in New Issue
Block a user