Skip to content

Commit

Permalink
Update the lib github.com/gofrs/uuid to v5 (#4169)
Browse files Browse the repository at this point in the history
Also, we will use UUIDv7, as they are more suitable for IDs in a
database (k-sortable property).
  • Loading branch information
nono authored Oct 17, 2023
2 parents caa2310 + 7c4e31c commit 8b285c4
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 109 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/dhowden/tag v0.0.0-20230630033851-978a0926ee25
github.com/dustin/go-humanize v1.0.1
github.com/gavv/httpexpect/v2 v2.16.0
github.com/gofrs/uuid v4.4.0+incompatible
github.com/gofrs/uuid/v5 v5.0.0
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/golang/gddo v0.0.0-20210115222349-20d68f94ee1f
github.com/goodsign/monday v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ github.com/go-stack/stack v1.6.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid/v5 v5.0.0 h1:p544++a97kEL+svbcFbCQVM9KFu0Yo25UoISXGNNH9M=
github.com/gofrs/uuid/v5 v5.0.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v4 v4.4.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
Expand Down
7 changes: 5 additions & 2 deletions model/bitwarden/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/cozy/cozy-stack/pkg/couchdb"
"github.com/cozy/cozy-stack/pkg/crypto"
"github.com/cozy/cozy-stack/pkg/metadata"
"github.com/gofrs/uuid/v5"
)

// DocTypeVersion represents the doctype version. Each time this document
Expand Down Expand Up @@ -103,16 +104,18 @@ func (s *Settings) EnsureCozyOrganization(inst *instance.Instance) error {
}
}
if s.OrganizationID == "" {
s.OrganizationID, err = couchdb.UUID(inst)
uid, err := uuid.NewV7()
if err != nil {
return err
}
s.OrganizationID = uid.String()
}
if s.CollectionID == "" {
s.CollectionID, err = couchdb.UUID(inst)
uid, err := uuid.NewV7()
if err != nil {
return err
}
s.CollectionID = uid.String()
}
return nil
}
Expand Down
9 changes: 4 additions & 5 deletions model/feature/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import (
"testing"

"github.com/cozy/cozy-stack/model/instance"
"github.com/gofrs/uuid"
"github.com/gofrs/uuid/v5"
"github.com/stretchr/testify/assert"
)

func uuidv4() string {
id, _ := uuid.NewV4()
return id.String()
func uuidv7() string {
return uuid.Must(uuid.NewV7()).String()
}

func TestFeatureFlagRatio(t *testing.T) {
inst := instance.Instance{
DocID: uuidv4(),
DocID: uuidv7(),
ContextName: "testing",
}
var data []interface{}
Expand Down
5 changes: 2 additions & 3 deletions model/instance/lifecycle/passphrase.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/cozy/cozy-stack/pkg/config/config"
"github.com/cozy/cozy-stack/pkg/crypto"
"github.com/cozy/cozy-stack/pkg/emailer"
"github.com/gofrs/uuid"
"github.com/gofrs/uuid/v5"
)

// ErrHintSameAsPassword is used when trying to set an hint that is the same as
Expand Down Expand Up @@ -335,6 +335,5 @@ func CheckHint(inst *instance.Instance, setting *settings.Settings, hint string)

// NewSecurityStamp returns a new UUID that can be used as a security stamp.
func NewSecurityStamp() string {
id, _ := uuid.NewV4()
return id.String()
return uuid.Must(uuid.NewV7()).String()
}
6 changes: 3 additions & 3 deletions model/note/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/cozy/cozy-stack/pkg/metadata"
"github.com/cozy/cozy-stack/pkg/prefixer"
"github.com/cozy/cozy-stack/pkg/realtime"
"github.com/gofrs/uuid"
"github.com/gofrs/uuid/v5"
)

// MaxWidth is the maximal width of an image for a note. If larger, the image
Expand Down Expand Up @@ -73,8 +73,8 @@ type ImageUpload struct {

// NewImageUpload can be used to manage uploading a new image for a note.
func NewImageUpload(inst *instance.Instance, note *vfs.FileDoc, name, mime string) (*ImageUpload, error) {
uuidv4, _ := uuid.NewV4()
id := note.ID() + "/" + uuidv4.String()
uuidv7, _ := uuid.NewV7()
id := note.ID() + "/" + uuidv7.String()
md := metadata.New()
md.CreatedByApp = consts.NotesSlug
img := &Image{DocID: id, Name: name, Mime: mime, Metadata: *md, originalName: name}
Expand Down
6 changes: 3 additions & 3 deletions model/note/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/cozy/cozy-stack/pkg/filetype"
"github.com/cozy/prosemirror-go/markdown"
"github.com/cozy/prosemirror-go/model"
"github.com/gofrs/uuid"
"github.com/gofrs/uuid/v5"
)

// MaxMarkdownSize is the maximal size of a markdown that can be parsed.
Expand All @@ -31,8 +31,8 @@ func ImportFile(inst *instance.Instance, newdoc, olddoc *vfs.FileDoc, body io.Re

// We need a fileID for saving images
if newdoc.ID() == "" {
uuidv4, _ := uuid.NewV4()
newdoc.SetID(uuidv4.String())
uuidv7, _ := uuid.NewV7()
newdoc.SetID(uuidv7.String())
}
images, _ := getImages(inst, newdoc.ID())

Expand Down
20 changes: 10 additions & 10 deletions model/sharing/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ func TestFiles(t *testing.T) {

t.Run("SharingDir", func(t *testing.T) {
s := Sharing{
SID: uuidv4(),
SID: uuidv7(),
Rules: []Rule{
{
Title: "Test sharing dir",
DocType: consts.Files,
Values: []string{uuidv4()},
Values: []string{uuidv7()},
},
},
}
Expand Down Expand Up @@ -116,17 +116,17 @@ func TestFiles(t *testing.T) {

t.Run("CreateDir", func(t *testing.T) {
s := Sharing{
SID: uuidv4(),
SID: uuidv7(),
Rules: []Rule{
{
Title: "Test create dir",
DocType: consts.Files,
Values: []string{uuidv4()},
Values: []string{uuidv7()},
},
},
}

idFoo := uuidv4()
idFoo := uuidv7()
target := map[string]interface{}{
"_id": idFoo,
"_rev": "1-6b501ca58928b02b90c430fd730e8b17",
Expand All @@ -148,7 +148,7 @@ func TestFiles(t *testing.T) {
assert.Equal(t, "/Tree Shared with me/Test create dir/Foo", dir.Fullpath)
}

idBar := uuidv4()
idBar := uuidv7()
target = map[string]interface{}{
"_id": idBar,
"_rev": "4-2ee767305024673cfb3f5af037cd2729",
Expand Down Expand Up @@ -181,17 +181,17 @@ func TestFiles(t *testing.T) {

t.Run("UpdateDir", func(t *testing.T) {
s := Sharing{
SID: uuidv4(),
SID: uuidv7(),
Rules: []Rule{
{
Title: "Test update dir",
DocType: consts.Files,
Values: []string{uuidv4()},
Values: []string{uuidv7()},
},
},
}

idFoo := uuidv4()
idFoo := uuidv7()
target := map[string]interface{}{
"_id": idFoo,
"_rev": "1-4fff5291a41bf1f493460d2070694c5a",
Expand Down Expand Up @@ -286,7 +286,7 @@ func TestFiles(t *testing.T) {
dir := createTree(t, inst.VFS(), tree, consts.RootDirID)

s := Sharing{
SID: uuidv4(),
SID: uuidv7(),
Rules: []Rule{
{
Title: "Test countFiles",
Expand Down
Loading

0 comments on commit 8b285c4

Please sign in to comment.