Implement 6-char progressive hash IDs (bd-166, bd-167)
- Hash ID generation now returns full 64-char SHA256 - Progressive collision handling: 6→7→8 chars on INSERT failure - Added child_counters table for hierarchical IDs - Updated all docs to reflect 6-char design - Collision math: 97% of 1K issues stay at 6 chars Next: Implement progressive retry logic in CreateIssue (bd-168) Amp-Thread-ID: https://ampcode.com/threads/T-9931c1b7-c989-47a1-8e6a-a04469bd937d Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -646,6 +646,23 @@ func (s *SQLiteStorage) AllocateNextID(ctx context.Context, prefix string) (stri
|
||||
return fmt.Sprintf("%s-%d", prefix, nextID), nil
|
||||
}
|
||||
|
||||
// getNextChildNumber atomically generates the next child number for a parent ID
|
||||
// Uses the child_counters table for atomic, cross-process child ID generation
|
||||
func (s *SQLiteStorage) getNextChildNumber(ctx context.Context, parentID string) (int, error) {
|
||||
var nextChild int
|
||||
err := s.db.QueryRowContext(ctx, `
|
||||
INSERT INTO child_counters (parent_id, last_child)
|
||||
VALUES (?, 1)
|
||||
ON CONFLICT(parent_id) DO UPDATE SET
|
||||
last_child = last_child + 1
|
||||
RETURNING last_child
|
||||
`, parentID).Scan(&nextChild)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to generate next child number for parent %s: %w", parentID, err)
|
||||
}
|
||||
return nextChild, nil
|
||||
}
|
||||
|
||||
// SyncAllCounters synchronizes all ID counters based on existing issues in the database
|
||||
// This scans all issues and updates counters to prevent ID collisions with auto-generated IDs
|
||||
// Note: This unconditionally overwrites counter values, allowing them to decrease after deletions
|
||||
|
||||
Reference in New Issue
Block a user