Azure / Azure/azure-sdk-tools

[APIView] WI-7: Comment FK & Backfill

Open
#14,998 0 comments 0 reactions 0 assignees View on GitHub
APIView
Dominant language
C#
Stars
135
Forks
260
Avg merge
3d 2h
Merged PRs (30d)
130

Description

## Goal

Every comment in the database has an `APIVersionId`, preparing for the query switch in WI-8.

**Area:** Comments · **Depends on:** WI-3 · **Stable alone:** ✅ Yes — adds a nullable field and populates it; nothing reads it yet

## Deliverables

### Add `APIVersionId` FK to comments

Add nullable `string? APIVersionId` to `CommentItemModel` in `LeanModels/CommentItemModel.cs`. Backward-compatible.

### Backfill

One-time migration:
1. Comments with `APIRevisionId != null`: look up revision (including soft-deleted), adopt its `APIVersionId`. If revision gone, timestamp-bracket to find version. Last resort: assign to latest stable version.
2. Comments with `APIRevisionId == null`: timestamp-bracket to find version.
3. Orphaned diagnostic comments (parent revision gone): hard-delete (machine-generated, revision-specific, no value without revision).

### Update comment creation paths (forward-write)

Ensure every new comment gets `APIVersionId`:
1. `CommentsManager.AddCommentAsync` — Look up revision's `APIVersionId`
2. `CommentsManager.SyncDiagnosticCommentsAsync` — Set `APIVersionId` from revision
3. `CommentsManager.CommentsBatchOperationAsync` — Replies inherit from thread root

### Tests

- `CommentsManagerTests.cs` — New comment gets `APIVersionId`; diagnostic sync; batch replies inherit from root
- `CommentBackfillTests.cs` — Revision lookup; deleted revision fallback; orphaned diagnostics deleted

Contributor guide

Open the contributing guide

Research direction

Start with LeanModels/CommentItemModel.cs and the three creation paths in CommentsManager: AddCommentAsync, SyncDiagnosticCommentsAsync, and CommentsBatchOperationAsync. Read CommentsManagerTests.cs and CommentBackfillTests.cs first to understand revision lookup, deleted-revision fallback, timestamp bracketing, inherited reply values, and orphan deletion. Done means the nullable foreign key is populated for existing and new comments and all listed tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.