From 01160082fa48ce3d1eb0c2856b737a9cdd32acea Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Sun, 2 Nov 2025 10:54:59 -0800 Subject: [PATCH] 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 --- cmd/bd/migrate.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cmd/bd/migrate.go b/cmd/bd/migrate.go index fec4618d..d7f8dd0c 100644 --- a/cmd/bd/migrate.go +++ b/cmd/bd/migrate.go @@ -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 {