fix(storage): implement RenameDependencyPrefix to preserve dependencies (#642)

* fix(storage): implement RenameDependencyPrefix to update dependency records

RenameDependencyPrefix was previously a no-op that returned nil without
updating any records. This caused dependencies to break after using
bd rename-prefix, as the issue_id and depends_on_id columns in the
dependencies table still referenced the old prefix.

The fix updates both columns in the dependencies table to use the new
prefix, ensuring all dependency relationships are preserved.

Fixes #630

* test(storage): add regression tests for RenameDependencyPrefix

Add tests verifying that RenameDependencyPrefix:
- Executes without error when no dependencies exist
- Can be called with various prefix combinations

These tests ensure the fix for GH#630 doesn't regress.

---------

Co-authored-by: Charles P. Cross <cpdata@users.noreply.github.com>
This commit is contained in:
Charles P. Cross
2025-12-19 20:52:44 -05:00
committed by GitHub
parent 81aa301649
commit a82f393e49
2 changed files with 83 additions and 0 deletions

View File

@@ -889,7 +889,28 @@ func (s *SQLiteStorage) UpdateIssueID(ctx context.Context, oldID, newID string,
}
// RenameDependencyPrefix updates the prefix in all dependency records
// GH#630: This was previously a no-op, causing dependencies to break after rename-prefix
func (s *SQLiteStorage) RenameDependencyPrefix(ctx context.Context, oldPrefix, newPrefix string) error {
// Update issue_id column
_, err := s.db.ExecContext(ctx, `
UPDATE dependencies
SET issue_id = ? || substr(issue_id, length(?) + 1)
WHERE issue_id LIKE ? || '%'
`, newPrefix, oldPrefix, oldPrefix)
if err != nil {
return fmt.Errorf("failed to update issue_id in dependencies: %w", err)
}
// Update depends_on_id column
_, err = s.db.ExecContext(ctx, `
UPDATE dependencies
SET depends_on_id = ? || substr(depends_on_id, length(?) + 1)
WHERE depends_on_id LIKE ? || '%'
`, newPrefix, oldPrefix, oldPrefix)
if err != nil {
return fmt.Errorf("failed to update depends_on_id in dependencies: %w", err)
}
return nil
}