Fix getNextID bug and design collision resolution (bd-9)
Critical bug fix: getNextID() was using alphabetical MAX instead of numerical MAX, causing "bd-9" to be treated as max when "bd-10" existed. This blocked all new issue creation after bd-10. Fixed by using SQL CAST to extract and compare numeric portions of IDs. This ensures bd-10 > bd-9 numerically, not alphabetically. Also completed comprehensive design for bd-9 (collision resolution): - Algorithm design with 7 phases (detection, scoring, remapping, etc.) - Created 7 child issues (bd-10, bd-12-17) breaking down implementation - Added design documents to .beads/ for future reference - Updated issues JSONL with new issues and dependencies Issues created: - bd-10: Export dependencies in JSONL - bd-12: Collision detection - bd-13: Reference scoring algorithm - bd-14: ID remapping with updates - bd-15: CLI flags and reporting - bd-16: Comprehensive tests - bd-17: Documentation updates - bd-18: Add design/notes fields to update command 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -59,28 +59,29 @@ func New(path string) (*SQLiteStorage, error) {
|
||||
|
||||
// getNextID determines the next issue ID to use
|
||||
func getNextID(db *sql.DB) int {
|
||||
var maxID sql.NullString
|
||||
err := db.QueryRow("SELECT MAX(id) FROM issues").Scan(&maxID)
|
||||
if err != nil {
|
||||
return 1 // Start from 1 if table is empty
|
||||
// Get prefix from config, default to "bd"
|
||||
var prefix string
|
||||
err := db.QueryRow("SELECT value FROM config WHERE key = 'issue_prefix'").Scan(&prefix)
|
||||
if err != nil || prefix == "" {
|
||||
prefix = "bd"
|
||||
}
|
||||
|
||||
if !maxID.Valid || maxID.String == "" {
|
||||
return 1
|
||||
// Find the maximum numeric ID for this prefix
|
||||
// Use SUBSTR to extract numeric part after prefix and hyphen, then CAST to INTEGER
|
||||
// This ensures we get numerical max, not alphabetical (bd-10 > bd-9, not bd-9 > bd-10)
|
||||
var maxNum sql.NullInt64
|
||||
query := `
|
||||
SELECT MAX(CAST(SUBSTR(id, LENGTH(?) + 2) AS INTEGER))
|
||||
FROM issues
|
||||
WHERE id LIKE ? || '-%'
|
||||
AND SUBSTR(id, 1, LENGTH(?)) = ?
|
||||
`
|
||||
err = db.QueryRow(query, prefix, prefix, prefix, prefix).Scan(&maxNum)
|
||||
if err != nil || !maxNum.Valid {
|
||||
return 1 // Start from 1 if table is empty or no matching IDs
|
||||
}
|
||||
|
||||
// Parse "bd-123" to get 123
|
||||
parts := strings.Split(maxID.String, "-")
|
||||
if len(parts) != 2 {
|
||||
return 1
|
||||
}
|
||||
|
||||
var num int
|
||||
if _, err := fmt.Sscanf(parts[1], "%d", &num); err != nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
return num + 1
|
||||
return int(maxNum.Int64) + 1
|
||||
}
|
||||
|
||||
// CreateIssue creates a new issue
|
||||
|
||||
Reference in New Issue
Block a user