Fix bd migrate to detect and set issue_prefix config

- Fixes GH #201
- bd migrate now detects prefix from existing issues
- Sets issue_prefix config before schema version update
- Prevents 'no issue found' errors after migration
- Prevents incorrect prefix in hash ID migrations

When migrating pre-0.17.5 databases, the issue_prefix config
(required since bd-166) was not being set. This caused commands
like 'bd show' to fail with 'no issue found' errors.

The fix queries for existing issues after migration and extracts
the prefix using utils.ExtractIssuePrefix(), then sets the config
before continuing with version updates.

Amp-Thread-ID: https://ampcode.com/threads/T-ba0c6c5c-8812-4ecf-8576-c0870fdbefff
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-11-02 10:54:59 -08:00
parent ad53c0bf4f
commit 01160082fa

View File

@@ -15,6 +15,7 @@ import (
"github.com/steveyegge/beads/internal/configfile"
"github.com/steveyegge/beads/internal/storage/sqlite"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/internal/utils"
_ "modernc.org/sqlite"
)
@@ -262,6 +263,34 @@ This command:
}
ctx := context.Background()
// Detect and set issue_prefix if missing (fixes GH #201)
prefix, err := store.GetConfig(ctx, "issue_prefix")
if err != nil || prefix == "" {
// Get first issue to detect prefix
issues, err := store.SearchIssues(ctx, "", types.IssueFilter{})
if err == nil && len(issues) > 0 {
detectedPrefix := utils.ExtractIssuePrefix(issues[0].ID)
if detectedPrefix != "" {
if err := store.SetConfig(ctx, "issue_prefix", detectedPrefix); err != nil {
_ = store.Close()
if jsonOutput {
outputJSON(map[string]interface{}{
"error": "prefix_detection_failed",
"message": err.Error(),
})
} else {
fmt.Fprintf(os.Stderr, "Error: failed to set issue prefix: %v\n", err)
}
os.Exit(1)
}
if !jsonOutput {
color.Green("✓ Detected and set issue prefix: %s\n", detectedPrefix)
}
}
}
}
if err := store.SetMetadata(ctx, "bd_version", Version); err != nil {
_ = store.Close()
if jsonOutput {