fix: Post-PR #8 critical improvements (bd-64, bd-65, bd-66, bd-67)
This commit addresses all critical follow-up issues identified in the code review of PR #8 (atomic counter implementation). ## bd-64: Fix SyncAllCounters performance bottleneck (P0) - Replace SyncAllCounters() on every CreateIssue with lazy initialization - Add ensureCounterInitialized() that only scans prefix-specific issues on first use - Performance improvement: O(n) full table scan → O(1) for subsequent creates - Add comprehensive tests in lazy_init_test.go ## bd-65: Add migration for issue_counters table (P1) - Add migrateIssueCountersTable() similar to migrateDirtyIssuesTable() - Checks if table is empty and syncs from existing issues on first open - Handles both fresh databases and migrations from old databases - Add comprehensive tests in migration_test.go (3 scenarios) ## bd-66: Make import counter sync failure fatal (P1) - Change SyncAllCounters() failure from warning to fatal error in import - Prevents ID collisions when counter sync fails - Data integrity > convenience ## bd-67: Update test comments (P2) - Update TestMultiProcessIDGeneration comments to reflect fix is in place - Change "With the bug, we expect errors" → "After the fix, all should succeed" All tests pass. Atomic counter implementation is now production-ready. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -240,9 +240,11 @@ Behavior:
|
||||
|
||||
// Phase 5: Sync ID counters after importing issues with explicit IDs
|
||||
// This prevents ID collisions with subsequently auto-generated issues
|
||||
// CRITICAL: If this fails, subsequent auto-generated IDs WILL collide with imported 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
|
||||
fmt.Fprintf(os.Stderr, "Error: failed to sync ID counters: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "Cannot proceed - auto-generated IDs would collide with imported issues.\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Phase 6: Process dependencies
|
||||
|
||||
Reference in New Issue
Block a user