GitHub Issue及评论ID是否全局唯一?
Hey folks, let's tackle this question head-on since it's make-or-break for your GitHub backup database design.
First, let's clarify the key ID behaviors you need to know:
ID Uniqueness Breakdown
- Issue
id: This is a GitHub-wide unique integer. No two issues (across any repo on the entire platform) will share the sameid. Even if an issue is closed, deleted, or moved, thatidis never reused. - Issue
number: This is per-repository sequential (e.g., #1, #2, #3 in your repo). It's what users see and reference, but it's only unique within your specific repo—another repo could have an issue with the samenumber. - Comment
id: Just like issueids, commentids are globally unique across GitHub. Every comment (on any issue, PR, or discussion) gets a uniqueidthat's never repeated, even if the comment is deleted.
How This Impacts Your Database Schema
Based on this, here's the solid schema approach:
- Issues Table:
- Use the GitHub Issue
idas your primary key. Since it's globally unique, you won't run into collisions even if you expand your backup to cover multiple repos later. - Keep the
numberfield as a secondary column—this is what users will recognize when looking at backups, so it's useful for display.
- Use the GitHub Issue
- Comments Table:
- Use the Comment
idas its primary key. - Add a foreign key column
issue_idthat links directly to theid(notnumber) in your Issues table. This guarantees you can always reliably map comments to their parent issues, no matter what changes happen in the original repo.
- Use the Comment
Why This Matters for Your Backup Workflow
Since these IDs are permanent and non-reusable, your backup database will stay consistent over time. You don't have to worry about a new issue or comment overwriting existing records—each entry gets a one-of-a-kind identifier from GitHub itself.
Quick note: When pulling data via the GitHub API or webhooks, prioritize using the
idfield for your database keys. Thenumberis great for user-facing views, but theidis the stable, unique value you need for backend storage.
内容的提问来源于stack exchange,提问作者nelsonic

