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:
v4rgas
2025-10-13 19:56:34 -03:00
committed by Steve Yegge
parent 187d291647
commit 73f5acadfa
4 changed files with 95 additions and 0 deletions

View File

@@ -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,