[management] fix index migration on mysql#6408
Conversation
📝 WalkthroughWalkthroughThis PR updates the ChangesPeer Key GORM Constraint Enforcement
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
management/server/peer/peer.go (1)
28-28: ⚡ Quick winConsider using 191 characters for broader MySQL compatibility.
While
size:255works for WireGuard public keys (which are 44 characters), MySQL databases using utf8mb4 withoutinnodb_large_prefixsupport have a 767-byte index key limit. With utf8mb4's 4-byte-per-character encoding, this translates to a maximum of 191 characters (191 × 4 = 764 bytes).Although 255 characters may work with modern MySQL configurations that have large prefix support enabled, using
size:191would provide better compatibility with older MySQL versions and stricter configurations.Since WireGuard public keys are only 44 characters, reducing the size to 191 would not impact functionality while improving database portability.
🔧 Suggested change for better MySQL compatibility
- Key string `gorm:"size:255;uniqueIndex"` + Key string `gorm:"size:191;uniqueIndex"`🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@management/server/peer/peer.go` at line 28, The GORM tag on the Peer struct's Key field uses size:255 which can exceed MySQL utf8mb4 indexed-key limits; change the struct field Key's gorm tag to use size:191 while keeping the uniqueIndex option (i.e., update the `Key string` field tag in peer.go from `gorm:"size:255;uniqueIndex"` to `gorm:"size:191;uniqueIndex"`) so indexes remain portable without affecting WireGuard key storage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@management/server/peer/peer.go`:
- Line 28: The GORM tag on the Peer struct's Key field uses size:255 which can
exceed MySQL utf8mb4 indexed-key limits; change the struct field Key's gorm tag
to use size:191 while keeping the uniqueIndex option (i.e., update the `Key
string` field tag in peer.go from `gorm:"size:255;uniqueIndex"` to
`gorm:"size:191;uniqueIndex"`) so indexes remain portable without affecting
WireGuard key storage.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 27fddde2-3c72-4cc5-b8be-b4d3f970edc5
📒 Files selected for processing (1)
management/server/peer/peer.go
Release artifactsBuilt for PR head
GHCR images (amd64)
This comment is updated by the Release workflow. Artifact links expire according to the workflow retention policy. |



Describe your changes
Following the PR from #5182
Issue ticket number and link
Stack
Checklist
Documentation
Select exactly one:
Docs PR URL (required if "docs added" is checked)
Paste the PR link from https://github.com/netbirdio/docs here:
https://github.com/netbirdio/docs/pull/__
Summary by CodeRabbit