fix: sync ID counters after import to prevent collisions
When importing issues with explicit high IDs (e.g., bd-100), the issue_counters table wasn't being updated. This caused the next auto-generated issue to collide with existing IDs (bd-4 instead of bd-101). Changes: - Add SyncAllCounters() to scan all issues and update counters atomically - Add SyncCounterForPrefix() for granular counter synchronization - Call SyncAllCounters() in import command after creating issues - Add comprehensive tests for counter sync functionality - Update TestImportCounterSyncAfterHighID to verify fix The fix uses a single efficient SQL query to prevent ID collisions with subsequently auto-generated issues.
This commit is contained in:
@@ -238,6 +238,13 @@ Behavior:
|
||||
}
|
||||
}
|
||||
|
||||
// Phase 4.5: Sync ID counters after importing issues with explicit IDs
|
||||
// This prevents ID collisions with subsequently auto-generated issues
|
||||
if err := sqliteStore.SyncAllCounters(ctx); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to sync ID counters: %v\n", err)
|
||||
// Don't exit - this is not fatal, just a warning
|
||||
}
|
||||
|
||||
// Phase 5: Process dependencies
|
||||
// Do this after all issues are created to handle forward references
|
||||
var depsCreated, depsSkipped int
|
||||
|
||||
@@ -1023,6 +1023,13 @@ func TestImportCounterSyncAfterHighID(t *testing.T) {
|
||||
t.Fatalf("Failed to import high ID issue: %v", err)
|
||||
}
|
||||
|
||||
// Step 4: Sync counters after import (mimics import command behavior)
|
||||
if err := testStore.SyncAllCounters(ctx); err != nil {
|
||||
t.Fatalf("Failed to sync counters: %v", err)
|
||||
}
|
||||
|
||||
// Step 5: Create another auto-generated issue
|
||||
// This should get bd-101 (counter should have synced to 100), not bd-4
|
||||
newIssue := &types.Issue{
|
||||
Title: "New issue after import",
|
||||
Status: types.StatusOpen,
|
||||
|
||||
Reference in New Issue
Block a user