Wire OrphanHandling through import pipeline (bd-8072)

- Added OrphanHandling type to sqlite package with 4 modes: strict/resurrect/skip/allow
- Updated EnsureIDs() to accept orphanHandling parameter and implement mode logic
- Added CreateIssuesWithOptions() that passes orphan handling through batch creation
- Made importer.OrphanHandling an alias to sqlite.OrphanHandling
- Importer now respects opts.OrphanHandling during batch issue creation

Next: Add import.orphan_handling config and wire through CLI commands
Amp-Thread-ID: https://ampcode.com/threads/T-bb7ffdd9-f444-4975-b5f7-bfff97cb92ff
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-11-04 23:53:44 -08:00
parent 09f2edafba
commit 0bf5c91cb3
4 changed files with 52 additions and 23 deletions

View File

@@ -13,18 +13,18 @@ import (
"github.com/steveyegge/beads/internal/utils"
)
// OrphanHandling defines how to handle missing parent issues during import
type OrphanHandling string
// OrphanHandling is an alias to sqlite.OrphanHandling for convenience
type OrphanHandling = sqlite.OrphanHandling
const (
// OrphanStrict fails import on missing parent (safest)
OrphanStrict OrphanHandling = "strict"
OrphanStrict = sqlite.OrphanStrict
// OrphanResurrect auto-resurrects missing parents from JSONL history
OrphanResurrect OrphanHandling = "resurrect"
OrphanResurrect = sqlite.OrphanResurrect
// OrphanSkip skips orphaned issues with warning
OrphanSkip OrphanHandling = "skip"
OrphanSkip = sqlite.OrphanSkip
// OrphanAllow imports orphans without validation (default, works around bugs)
OrphanAllow OrphanHandling = "allow"
OrphanAllow = sqlite.OrphanAllow
)
// Options contains import configuration
@@ -566,14 +566,14 @@ if len(newIssues) > 0 {
// Create in batches by depth level (max depth 3)
for depth := 0; depth <= 3; depth++ {
var batchForDepth []*types.Issue
for _, issue := range newIssues {
if strings.Count(issue.ID, ".") == depth {
batchForDepth = append(batchForDepth, issue)
var batchForDepth []*types.Issue
for _, issue := range newIssues {
if strings.Count(issue.ID, ".") == depth {
batchForDepth = append(batchForDepth, issue)
}
}
if len(batchForDepth) > 0 {
if err := sqliteStore.CreateIssues(ctx, batchForDepth, "import"); err != nil {
if err := sqliteStore.CreateIssuesWithOptions(ctx, batchForDepth, "import", opts.OrphanHandling); err != nil {
return fmt.Errorf("error creating depth-%d issues: %w", depth, err)
}
result.Created += len(batchForDepth)