feat(import): add import.orphan_handling config with 4 modes
- Add GetOrphanHandling() helper to SQLiteStorage (reads from config table) - Add --orphan-handling flag to 'bd import' command - Wire OrphanHandling through ImportOptions -> importer.Options - Auto-read config if flag not provided (default: 'allow') - Document in CONFIG.md with detailed mode explanations Modes: - strict: Fail on missing parent (safest) - resurrect: Auto-create parent tombstones from JSONL - skip: Skip orphans with warning - allow: Import without validation (default, most permissive) Closes bd-8072, bd-b92a Amp-Thread-ID: https://ampcode.com/threads/T-fd18d4a5-06b3-4400-9073-194d570846d8 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -97,6 +97,11 @@ func ImportIssues(ctx context.Context, dbPath string, store storage.Storage, iss
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to clear export_hashes before import: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Read orphan handling from config if not explicitly set
|
||||
if opts.OrphanHandling == "" {
|
||||
opts.OrphanHandling = sqliteStore.GetOrphanHandling(ctx)
|
||||
}
|
||||
|
||||
// Check and handle prefix mismatches
|
||||
if err := handlePrefixMismatch(ctx, sqliteStore, issues, opts, result); err != nil {
|
||||
|
||||
@@ -1208,6 +1208,22 @@ func (s *SQLiteStorage) DeleteConfig(ctx context.Context, key string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// GetOrphanHandling gets the import.orphan_handling config value
|
||||
// Returns OrphanAllow (the default) if not set or if value is invalid
|
||||
func (s *SQLiteStorage) GetOrphanHandling(ctx context.Context) OrphanHandling {
|
||||
value, err := s.GetConfig(ctx, "import.orphan_handling")
|
||||
if err != nil || value == "" {
|
||||
return OrphanAllow // Default
|
||||
}
|
||||
|
||||
switch OrphanHandling(value) {
|
||||
case OrphanStrict, OrphanResurrect, OrphanSkip, OrphanAllow:
|
||||
return OrphanHandling(value)
|
||||
default:
|
||||
return OrphanAllow // Invalid value, use default
|
||||
}
|
||||
}
|
||||
|
||||
// SetMetadata sets a metadata value (for internal state like import hashes)
|
||||
func (s *SQLiteStorage) SetMetadata(ctx context.Context, key, value string) error {
|
||||
_, err := s.db.ExecContext(ctx, `
|
||||
|
||||
Reference in New Issue
Block a user