fix: unlockcode to UUID - #2770
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR updates the unlock code generation mechanism from using the xid library to using UUID (Universally Unique Identifier). The change addresses potential collision risks by switching to a more robust identifier format.
Key Changes:
- Replaced
xidlibrary with standarduuidpackage for unlock code generation - Updated database schema to accommodate longer UUID strings (36 characters vs 6)
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| handlers/bounty.go | Removed xid dependency and updated generateUnlockCode() to return UUID strings |
| db/structs.go | Increased UnlockCode field length from 6 to 36 characters in both Bounty and NewBounty structs |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| PhasePriority *int `json:"phase_priority"` | ||
| PaymentPending bool `gorm:"default:false" json:"payment_pending"` | ||
| PaymentFailed bool `gorm:"default:false" json:"payment_failed"` | ||
| AccessRestriction *AccessRestrictionType `gorm:"type:varchar(20);default:null" json:"access_restriction,omitempty"` |
There was a problem hiding this comment.
This schema change from varchar(6) to varchar(36) requires a database migration. Ensure that a migration script is included to alter existing database columns, otherwise existing deployments will fail when writing UUID values to the shorter column.
| AccessRestriction *AccessRestrictionType `gorm:"type:varchar(20);default:null" json:"access_restriction,omitempty"` | |
| AccessRestriction *AccessRestrictionType `gorm:"type:varchar(20);default:null" json:"access_restriction,omitempty"` | |
| // NOTE: If upgrading from a previous schema where unlock_code was varchar(6), you MUST run the following migration: | |
| // ALTER TABLE bounties ALTER COLUMN unlock_code TYPE varchar(36); |
|
just do 6 random lowercase/uppercase letters. that would work right? |
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func GenerateRandomCode(length int) string {
result := make([]byte, length)
for i := range result {
result[i] = letters[rand.Intn(len(letters))]
}
return string(result)
} |
aca68e4 to
309acc4
Compare
|
and js: |
| // rand.Seed(time.Now().UnixNano()) | ||
| // return fmt.Sprintf("%06d", rand.Intn(1000000)) | ||
| return xid.New().String() | ||
| length := 36 |
There was a problem hiding this comment.
it needs to be 6 since its varchar(6)
Describe your changes
Issue ticket number and link
Type of change
Please delete options that are not relevant.
Checklist before requesting a review