-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[management] fix domain uniqueness #5529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mirror the new domain length limit in
Validate().Line 137 now caps the column at 255 characters, but
Validate()still only checks thatDomainis non-empty. Overlong values will fail later with a DB error instead of a validation error.💡 Proposed fix
func (s *Service) Validate() error { if s.Name == "" { return errors.New("service name is required") } if len(s.Name) > 255 { return errors.New("service name exceeds maximum length of 255 characters") } if s.Domain == "" { return errors.New("service domain is required") } + if len(s.Domain) > 255 { + return errors.New("service domain exceeds maximum length of 255 characters") + } if len(s.Targets) == 0 { return errors.New("at least one target is required") }📝 Committable suggestion
🤖 Prompt for AI Agents
🧩 Analysis chain
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 123
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 147
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 260
🌐 Web query:
GORM v2 AutoMigrate index to uniqueIndex upgrade behavior💡 Result:
In GORM v2,
AutoMigrateis not an “alter everything to match tags” schema diff. It mainly creates what’s missing (tables/columns/indexes/constraints) and won’t reliably “upgrade” an existing non-unique index into a unique one for you. (gorm.io)What happens if you change
gorm:"index"→gorm:"uniqueIndex"AutoMigratewill typically try to create a new unique index (often with a different name), and leave the old non-unique index in place (because it doesn’t treat that as a “missing index” vs “needs alteration” case). (gorm.io)name, thenname_2,name_3, …). (github.com)Practical takeaway / recommended migration approach
If you truly need to “upgrade” to unique, do it as an explicit migration:
uniqueIndex:your_name).AutoMigratecan keep doing additive changes safely. (gorm.io)Citations:
AutoMigratego-gorm/gorm#6224🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 5737
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 1705
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 10390
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 43
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 2638
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 373
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 3072
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 91
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 2999
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 43
🏁 Script executed:
# Check the git commit that updated the type git show ccbd554b --statRepository: netbirdio/netbird
Length of output: 50374
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 43
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 43
🏁 Script executed:
# Look at the full migration.go file to see all available migration helpers wc -l management/server/migration/migration.goRepository: netbirdio/netbird
Length of output: 105
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 394
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 43
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 106
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 3597
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 1028
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 43
🏁 Script executed:
Repository: netbirdio/netbird
Length of output: 43
Add an explicit migration to handle the Domain field index change.
GORM v2's
AutoMigratedoes not reliably convert existing non-unique indexes to unique ones. When the Domain field tag changes fromgorm:"index"togorm:"uniqueIndex", AutoMigrate may create a new unique index while leaving the old non-unique one in place, resulting in duplicate indexes without enforcing the uniqueness guarantee on existing data.Add an explicit migration in
getMigrationsPostAuto()(management/server/store/store.go) to:This ensures older installations properly enforce the uniqueness constraint on upgrade.
🤖 Prompt for AI Agents