Make hash IDs opt-in via id_mode config (bd-5404)

- Add id_mode config (sequential|hash), defaults to sequential
- Update CreateIssue/CreateIssues to check id_mode and generate appropriate IDs
- Implement lazy counter initialization from existing issues
- Update migrate --to-hash-ids to set id_mode=hash after migration
- Fix hash ID tests to set id_mode=hash
- Fix renumber test to use explicit IDs
- All 183 test packages pass

This makes hash IDs backward-compatible opt-in rather than forced default.
This commit is contained in:
Steve Yegge
2025-10-30 16:50:38 -07:00
parent 0858bdb7ed
commit 1fbfe58ba7
5 changed files with 145 additions and 55 deletions

View File

@@ -356,6 +356,22 @@ This command:
color.Green("✓ Migrated %d issues to hash-based IDs\n", len(mapping))
}
}
// Set id_mode=hash after successful migration (not in dry-run)
if !dryRun {
store, err := sqlite.New(targetPath)
if err == nil {
ctx := context.Background()
if err := store.SetConfig(ctx, "id_mode", "hash"); err != nil {
if !jsonOutput {
fmt.Fprintf(os.Stderr, "Warning: failed to set id_mode=hash: %v\n", err)
}
} else if !jsonOutput {
color.Green("✓ Switched database to hash ID mode\n")
}
store.Close()
}
}
} else {
store.Close()
if !jsonOutput {

View File

@@ -44,6 +44,7 @@ func TestRenumberWithGaps(t *testing.T) {
for _, tc := range testIssues {
issue := &types.Issue{
ID: tc.id, // Set explicit ID to simulate gaps
Title: tc.title,
Description: "Test issue for renumbering",
Priority: 1,
@@ -53,10 +54,6 @@ func TestRenumberWithGaps(t *testing.T) {
if err := testStore.CreateIssue(ctx, issue, "test"); err != nil {
t.Fatalf("failed to create issue: %v", err)
}
// Manually update ID to simulate gaps
if err := testStore.UpdateIssueID(ctx, issue.ID, tc.id, issue, "test"); err != nil {
t.Fatalf("failed to set issue ID to %s: %v", tc.id, err)
}
}
// Add a dependency to test that it gets updated