beads/internal/storage/batch.go
Julian Knutsen d59200bd39
refactor: delete the dead orphan-handling capability (bd-gwryr) (#5497)
BatchCreateOptions.OrphanHandling had four modes and one behavior. Every
production call site passed OrphanAllow (or left the field at its zero
value, which took the same branch), so CheckOrphan returned (false, nil)
on every path it could reach — after paying a SELECT COUNT(*)
parent-existence probe on every hierarchical-ID create to feed a switch
whose only reachable arm ignored the answer.

OrphanStrict and OrphanSkip were reachable from exactly one conformance
case, testAuditCreateOrphanHandling, which existed to execute them.
OrphanResurrect was never a branch at all: it shared the default arm with
OrphanAllow, and the "auto-resurrects missing parents from database
history" behavior its doc comment described left with the JSONL sync
layer. internal/beads' TestImportWithDeletedParent still asserted that
removed behavior; it goes too.

This removes the type, the four constants, the field, CheckOrphan and its
call site, the backend package's alias and re-exports (a breaking change
to a published package, signed off by the owner), the dead
ImportOptions.OrphanHandling, and the import.orphan_handling row in the
yaml-only-key test — replaced with import.unlisted-key, which keeps the
"import.* is exact-match, not a prefix namespace" assertion the row was
actually providing.

The behavior that remains is what OrphanAllow always did: a hierarchical
create whose parent is missing is accepted, and the child's auxiliary
counter row is skipped because it would have no owner
(TestReconcileChildCountersSkipsMissingParent pins that). The wasted
query is gone from the create path.

Co-authored-by: CI Bot <ci@beads.test>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-09 12:03:18 -07:00

43 lines
2.5 KiB
Go

// Package storage defines the interface for issue storage backends.
package storage
// BatchCreateOptions contains options for batch issue creation.
// This is a backend-agnostic type that can be used by any storage implementation.
type BatchCreateOptions struct {
// CreateOnly uses strict insert semantics after the caller has reserved the
// issue ID. It is for guarded public creates; import behavior is unchanged.
CreateOnly bool
// SkipPrefixValidation skips prefix validation for existing IDs (used during import)
SkipPrefixValidation bool
// ConflictSkip makes batch creation insert-if-new instead of UPSERT: an
// issue whose ID already exists is left untouched rather than overwritten.
// Used only by the auto-import upgrade-recovery fallback (GH#3955), so
// that if the emptiness guard in maybeAutoImportJSONL ever regresses
// again (cf. PR #3630), auto-import degrades to a harmless no-op instead
// of clobbering live rows. Explicit `bd import` keeps UPSERT semantics.
ConflictSkip bool
// RejectStaleUpserts makes the issue-row UPSERT conditional on updated_at:
// the incoming row only rewrites the stored columns when it is strictly
// newer. A stored row that is strictly newer is rejected outright
// (OnStaleRejected fires, aux data skipped); an equal-timestamp row keeps
// every stored column but still merges its aux data — updated_at has
// second granularity, so a tie may be two distinct same-second updates
// and the local row wins it (bd-hj85c). This is the transactional half
// of the import stale guard (bd-pkim8): cmd/bd's filterStaleImportIssues
// reads local updated_at before the batch write, so a local update
// committing in between would otherwise be silently overwritten (the
// PR 4204 race). Set by `bd import` unless --allow-stale; create paths
// leave it false.
RejectStaleUpserts bool
// SkipDependencyValidationErrors skips dependency validation failures that
// legacy imports tolerated, such as cycles or self-dependencies.
SkipDependencyValidationErrors bool
// OnSkippedDependency records dependency edges skipped during batch create.
OnSkippedDependency func(issueID, dependsOnID, reason string)
// OnStaleRejected records issues whose row the RejectStaleUpserts guard
// kept (stored row strictly newer than the incoming one). Rejected issues
// also skip label/comment/dependency persistence, so callers can count
// them as skipped rather than created. May fire more than once per issue
// if the enclosing transaction retries; callers should dedup by ID.
OnStaleRejected func(issueID string)
}