Fix bd migrate loop: skip prefix validation during auto-import

When auto-importing issues from JSONL, issues with different prefixes
(e.g., gt-1 vs gastown-) would fail validation and cause an infinite
loop of failed migrations.

The fix adds SkipPrefixValidation option to CreateIssuesWithFullOptions
which propagates through EnsureIDs to skip prefix validation for issues
that already have IDs during import. This allows importing issues with
any prefix while still validating new issues created interactively.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-11-27 21:45:42 -08:00
parent 7447a5004c
commit 22d34a22dc
4 changed files with 50 additions and 10 deletions

View File

@@ -187,15 +187,19 @@ func tryResurrectParent(parentID string, issues []*types.Issue) bool {
// For issues with empty IDs, generates unique hash-based IDs
// For issues with existing IDs, validates they match the prefix and parent exists (if hierarchical)
// For hierarchical IDs with missing parents, behavior depends on orphanHandling mode
func EnsureIDs(ctx context.Context, conn *sql.Conn, prefix string, issues []*types.Issue, actor string, orphanHandling OrphanHandling) error {
// When skipPrefixValidation is true, existing IDs are not validated against the prefix (used during import)
func EnsureIDs(ctx context.Context, conn *sql.Conn, prefix string, issues []*types.Issue, actor string, orphanHandling OrphanHandling, skipPrefixValidation bool) error {
usedIDs := make(map[string]bool)
// First pass: record explicitly provided IDs
for i := range issues {
if issues[i].ID != "" {
// Validate that explicitly provided ID matches the configured prefix (bd-177)
if err := ValidateIssueIDPrefix(issues[i].ID, prefix); err != nil {
return wrapDBErrorf(err, "validate ID prefix for %s", issues[i].ID)
// Skip validation during import to allow issues with different prefixes (e.g., from renamed repos)
if !skipPrefixValidation {
if err := ValidateIssueIDPrefix(issues[i].ID, prefix); err != nil {
return wrapDBErrorf(err, "validate ID prefix for %s", issues[i].ID)
}
}
// For hierarchical IDs (bd-a3f8e9.1), ensure parent exists