Skip to content

Commit 75946eb

Browse files
committed
Update: 全ての UUIDv4 の生成を UUIDv7 に置き換え
1 parent 4ac1640 commit 75946eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+103
-103
lines changed

model/users_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func TestAuthenticateUser(t *testing.T) {
2828
tt := []UserInfo{
2929
&User{Bot: true},
3030
&User{},
31-
&User{Password: hex.EncodeToString(uuid.Must(uuid.NewV4()).Bytes()), Salt: "アイウエオ"},
32-
&User{Salt: hex.EncodeToString(uuid.Must(uuid.NewV4()).Bytes()), Password: "アイウエオ"},
33-
&User{Salt: hex.EncodeToString(uuid.Must(uuid.NewV4()).Bytes()), Password: hex.EncodeToString(uuid.Must(uuid.NewV4()).Bytes())},
31+
&User{Password: hex.EncodeToString(uuid.Must(uuid.NewV7()).Bytes()), Salt: "アイウエオ"},
32+
&User{Salt: hex.EncodeToString(uuid.Must(uuid.NewV7()).Bytes()), Password: "アイウエオ"},
33+
&User{Salt: hex.EncodeToString(uuid.Must(uuid.NewV7()).Bytes()), Password: hex.EncodeToString(uuid.Must(uuid.NewV7()).Bytes())},
3434
}
3535
for _, u := range tt {
3636
assert.Error(u.Authenticate("test"))

model/webhooks_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ func TestWebhookBot_TableName(t *testing.T) {
1515

1616
func TestWebhookBot_GetID(t *testing.T) {
1717
t.Parallel()
18-
id := uuid.Must(uuid.NewV4())
18+
id := uuid.Must(uuid.NewV7())
1919
assert.Equal(t, id, (&WebhookBot{ID: id}).GetID())
2020
}
2121

2222
func TestWebhookBot_GetChannelID(t *testing.T) {
2323
t.Parallel()
24-
id := uuid.Must(uuid.NewV4())
24+
id := uuid.Must(uuid.NewV7())
2525
assert.Equal(t, id, (&WebhookBot{ChannelID: id}).GetChannelID())
2626
}
2727

2828
func TestWebhookBot_GetBotUserID(t *testing.T) {
2929
t.Parallel()
30-
id := uuid.Must(uuid.NewV4())
30+
id := uuid.Must(uuid.NewV7())
3131
assert.Equal(t, id, (&WebhookBot{BotUserID: id}).GetBotUserID())
3232
}
3333

3434
func TestWebhookBot_GetCreatorID(t *testing.T) {
3535
t.Parallel()
36-
id := uuid.Must(uuid.NewV4())
36+
id := uuid.Must(uuid.NewV7())
3737
assert.Equal(t, id, (&WebhookBot{CreatorID: id}).GetCreatorID())
3838
}
3939

repository/gorm/bot.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import (
1818

1919
// CreateBot implements BotRepository interface.
2020
func (repo *Repository) CreateBot(name, displayName, description string, iconFileID, creatorID uuid.UUID, mode model.BotMode, state model.BotState, webhookURL string) (*model.Bot, error) {
21-
uid := uuid.Must(uuid.NewV4())
22-
bid := uuid.Must(uuid.NewV4())
23-
tid := uuid.Must(uuid.NewV4())
21+
uid := uuid.Must(uuid.NewV7())
22+
bid := uuid.Must(uuid.NewV7())
23+
tid := uuid.Must(uuid.NewV7())
2424
u := &model.User{
2525
ID: uid,
2626
Name: "BOT_" + name,
@@ -296,7 +296,7 @@ func (repo *Repository) ReissueBotTokens(id uuid.UUID) (*model.Bot, error) {
296296
return err
297297
}
298298

299-
tid := uuid.Must(uuid.NewV4())
299+
tid := uuid.Must(uuid.NewV7())
300300
scopes := model.AccessScopes{}
301301
scopes.Add("bot")
302302
t := &model.OAuth2Token{

repository/gorm/channel.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var dmChannelRootUUID = uuid.Must(uuid.FromString(model.DirectMessageChannelRoot
2121
func (repo *Repository) CreateChannel(ch model.Channel, privateMembers set.UUID, dm bool) (*model.Channel, error) {
2222
arr := []interface{}{&ch}
2323

24-
ch.ID = uuid.Must(uuid.NewV4())
24+
ch.ID = uuid.Must(uuid.NewV7())
2525
ch.IsPublic = true
2626
ch.DeletedAt = gorm.DeletedAt{}
2727

@@ -436,7 +436,7 @@ func (repo *Repository) GetChannelEvents(query repository.ChannelEventsQuery) (e
436436
// RecordChannelEvent implements ChannelRepository interface.
437437
func (repo *Repository) RecordChannelEvent(channelID uuid.UUID, eventType model.ChannelEventType, detail model.ChannelEventDetail, datetime time.Time) error {
438438
return repo.db.Create(&model.ChannelEvent{
439-
EventID: uuid.Must(uuid.NewV4()),
439+
EventID: uuid.Must(uuid.NewV7()),
440440
ChannelID: channelID,
441441
EventType: eventType,
442442
Detail: detail,

repository/gorm/channel_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func TestGormRepository_ChangeChannelSubscription(t *testing.T) {
108108
Subscription: map[uuid.UUID]model.ChannelSubscribeLevel{
109109
user1.GetID(): model.ChannelSubscribeLevelMarkAndNotify,
110110
user2.GetID(): model.ChannelSubscribeLevelMarkAndNotify,
111-
uuid.Must(uuid.NewV4()): model.ChannelSubscribeLevelMarkAndNotify,
111+
uuid.Must(uuid.NewV7()): model.ChannelSubscribeLevelMarkAndNotify,
112112
},
113113
}
114114
_, _, err := repo.ChangeChannelSubscription(ch.ID, args)
@@ -120,7 +120,7 @@ func TestGormRepository_ChangeChannelSubscription(t *testing.T) {
120120
Subscription: map[uuid.UUID]model.ChannelSubscribeLevel{
121121
user1.GetID(): model.ChannelSubscribeLevelMarkAndNotify,
122122
user2.GetID(): model.ChannelSubscribeLevelNone,
123-
uuid.Must(uuid.NewV4()): model.ChannelSubscribeLevelNone,
123+
uuid.Must(uuid.NewV7()): model.ChannelSubscribeLevelNone,
124124
},
125125
}
126126
_, _, err = repo.ChangeChannelSubscription(ch.ID, args)
@@ -144,7 +144,7 @@ func TestGormRepository_GetChannelStats(t *testing.T) {
144144
t.Run("not found", func(t *testing.T) {
145145
t.Parallel()
146146

147-
_, err := repo.GetChannelStats(uuid.Must(uuid.NewV4()))
147+
_, err := repo.GetChannelStats(uuid.Must(uuid.NewV7()))
148148
assert.Error(t, err)
149149
})
150150

repository/gorm/clip.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (repo *Repository) CreateClipFolder(userID uuid.UUID, name string, descript
1919
return nil, repository.ErrNilID
2020
}
2121

22-
uid := uuid.Must(uuid.NewV4())
22+
uid := uuid.Must(uuid.NewV7())
2323
clipFolder := &model.ClipFolder{
2424
ID: uid,
2525
Description: description,

repository/gorm/clip_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestRepositoryImpl_UpdateClipFolder(t *testing.T) {
6262
t.Parallel()
6363
assert := assert.New(t)
6464

65-
assert.EqualError(repo.UpdateClipFolder(uuid.Must(uuid.NewV4()), optional.Of[string]{}, optional.Of[string]{}), repository.ErrNotFound.Error())
65+
assert.EqualError(repo.UpdateClipFolder(uuid.Must(uuid.NewV7()), optional.Of[string]{}, optional.Of[string]{}), repository.ErrNotFound.Error())
6666
})
6767

6868
t.Run("no change", func(t *testing.T) {
@@ -103,7 +103,7 @@ func TestRepositoryImpl_DeleteClipFolder(t *testing.T) {
103103
t.Parallel()
104104
assert := assert.New(t)
105105

106-
assert.EqualError(repo.DeleteClipFolder(uuid.Must(uuid.NewV4())), repository.ErrNotFound.Error())
106+
assert.EqualError(repo.DeleteClipFolder(uuid.Must(uuid.NewV7())), repository.ErrNotFound.Error())
107107
})
108108

109109
t.Run("success", func(t *testing.T) {
@@ -135,7 +135,7 @@ func TestRepositoryImpl_DeleteClipFolderMessage(t *testing.T) {
135135
t.Parallel()
136136
assert := assert.New(t)
137137

138-
assert.EqualError(repo.DeleteClipFolderMessage(uuid.Must(uuid.NewV4()), uuid.Must(uuid.NewV4())), repository.ErrNotFound.Error())
138+
assert.EqualError(repo.DeleteClipFolderMessage(uuid.Must(uuid.NewV7()), uuid.Must(uuid.NewV7())), repository.ErrNotFound.Error())
139139
})
140140

141141
t.Run("success", func(t *testing.T) {
@@ -168,7 +168,7 @@ func TestRepositoryImpl_AddClipFolderMessage(t *testing.T) {
168168
t.Run("not found", func(t *testing.T) {
169169
t.Parallel()
170170
assert := assert.New(t)
171-
_, err := repo.AddClipFolderMessage(uuid.Must(uuid.NewV4()), uuid.Must(uuid.NewV4()))
171+
_, err := repo.AddClipFolderMessage(uuid.Must(uuid.NewV7()), uuid.Must(uuid.NewV7()))
172172
assert.EqualError(err, repository.ErrNotFound.Error())
173173
})
174174

@@ -250,7 +250,7 @@ func TestRepositoryImpl_GetClipFolder(t *testing.T) {
250250
t.Parallel()
251251
assert := assert.New(t)
252252

253-
_, err := repo.GetClipFolder(uuid.Must(uuid.NewV4()))
253+
_, err := repo.GetClipFolder(uuid.Must(uuid.NewV7()))
254254
assert.EqualError(err, repository.ErrNotFound.Error())
255255
})
256256

repository/gorm/file_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestGormRepository_SaveFileMeta(t *testing.T) {
2424
t.Run("success", func(t *testing.T) {
2525
t.Parallel()
2626
meta := &model.FileMeta{
27-
ID: uuid.Must(uuid.NewV4()),
27+
ID: uuid.Must(uuid.NewV7()),
2828
Name: "dummy",
2929
Mime: "application/octet-stream",
3030
Size: 10,
@@ -153,7 +153,7 @@ func TestGormRepository_IsFileAccessible(t *testing.T) {
153153
t.Parallel()
154154

155155
meta := &model.FileMeta{
156-
ID: uuid.Must(uuid.NewV4()),
156+
ID: uuid.Must(uuid.NewV7()),
157157
Name: "dummy",
158158
Mime: "application/octet-stream",
159159
Size: 10,
@@ -199,7 +199,7 @@ func TestGormRepository_IsFileAccessible(t *testing.T) {
199199

200200
user2 := mustMakeUser(t, repo, rand)
201201
meta := &model.FileMeta{
202-
ID: uuid.Must(uuid.NewV4()),
202+
ID: uuid.Must(uuid.NewV7()),
203203
Name: "dummy",
204204
Mime: "application/octet-stream",
205205
Size: 10,
@@ -255,7 +255,7 @@ func TestGormRepository_IsFileAccessible(t *testing.T) {
255255

256256
deniedUser := mustMakeUser(t, repo, rand)
257257
meta := &model.FileMeta{
258-
ID: uuid.Must(uuid.NewV4()),
258+
ID: uuid.Must(uuid.NewV7()),
259259
Name: "dummy",
260260
Mime: "application/octet-stream",
261261
Size: 10,

repository/gorm/message.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (repo *Repository) CreateMessage(userID, channelID uuid.UUID, text string)
2222
}
2323

2424
m := &model.Message{
25-
ID: uuid.Must(uuid.NewV4()),
25+
ID: uuid.Must(uuid.NewV7()),
2626
UserID: userID,
2727
ChannelID: channelID,
2828
Text: text,
@@ -87,7 +87,7 @@ func (repo *Repository) UpdateMessage(messageID uuid.UUID, text string) error {
8787

8888
// archiving
8989
if err := tx.Create(&model.ArchivedMessage{
90-
ID: uuid.Must(uuid.NewV4()),
90+
ID: uuid.Must(uuid.NewV7()),
9191
MessageID: oldMes.ID,
9292
UserID: oldMes.UserID,
9393
Text: oldMes.Text,

repository/gorm/message_report.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (repo *Repository) CreateMessageReport(messageID, reporterID uuid.UUID, rea
1717

1818
// make report
1919
r := &model.MessageReport{
20-
ID: uuid.Must(uuid.NewV4()),
20+
ID: uuid.Must(uuid.NewV7()),
2121
MessageID: messageID,
2222
Reporter: reporterID,
2323
Reason: reason,

repository/gorm/message_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestRepositoryImpl_UpdateMessage(t *testing.T) {
8181
m := mustMakeMessage(t, repo, user.GetID(), channel.ID)
8282
originalText := m.Text
8383

84-
assert.EqualError(repo.UpdateMessage(uuid.Must(uuid.NewV4()), "new message"), repository.ErrNotFound.Error())
84+
assert.EqualError(repo.UpdateMessage(uuid.Must(uuid.NewV7()), "new message"), repository.ErrNotFound.Error())
8585
assert.EqualError(repo.UpdateMessage(uuid.Nil, "new message"), repository.ErrNilID.Error())
8686
assert.NoError(repo.UpdateMessage(m.ID, "new message"))
8787

@@ -121,7 +121,7 @@ func TestRepositoryImpl_GetMessageByID(t *testing.T) {
121121
_, err = repo.GetMessageByID(uuid.Nil)
122122
assert.Error(err)
123123

124-
_, err = repo.GetMessageByID(uuid.Must(uuid.NewV4()))
124+
_, err = repo.GetMessageByID(uuid.Must(uuid.NewV7()))
125125
assert.Error(err)
126126
}
127127

repository/gorm/oauth2.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (repo *Repository) DeleteAuthorize(code string) error {
138138
// IssueToken implements OAuth2Repository interface.
139139
func (repo *Repository) IssueToken(client *model.OAuth2Client, userID uuid.UUID, redirectURI string, scope model.AccessScopes, expire int, refresh bool) (*model.OAuth2Token, error) {
140140
newToken := &model.OAuth2Token{
141-
ID: uuid.Must(uuid.NewV4()),
141+
ID: uuid.Must(uuid.NewV7()),
142142
UserID: userID,
143143
RedirectURI: redirectURI,
144144
AccessToken: random.SecureAlphaNumeric(36),

repository/gorm/pin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (repo *Repository) PinMessage(messageID, userID uuid.UUID) (*model.Pin, err
2525
return convertError(err)
2626
}
2727

28-
p = model.Pin{ID: uuid.Must(uuid.NewV4()), MessageID: messageID, UserID: userID}
28+
p = model.Pin{ID: uuid.Must(uuid.NewV7()), MessageID: messageID, UserID: userID}
2929
if err := tx.Create(&p).Error; err != nil {
3030
if gormutil.IsMySQLDuplicatedRecordErr(err) {
3131
return repository.ErrAlreadyExists

repository/gorm/pin_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ func TestRepositoryImpl_PinMessage(t *testing.T) {
2323
t.Run("nil id (user)", func(t *testing.T) {
2424
t.Parallel()
2525

26-
_, err := repo.PinMessage(uuid.Must(uuid.NewV4()), uuid.Nil)
26+
_, err := repo.PinMessage(uuid.Must(uuid.NewV7()), uuid.Nil)
2727
assert.Error(t, err)
2828
})
2929

3030
t.Run("message not found", func(t *testing.T) {
3131
t.Parallel()
3232

33-
_, err := repo.PinMessage(uuid.Must(uuid.NewV4()), user.GetID())
33+
_, err := repo.PinMessage(uuid.Must(uuid.NewV7()), user.GetID())
3434
assert.EqualError(t, err, repository.ErrNotFound.Error())
3535
})
3636

@@ -68,7 +68,7 @@ func TestRepositoryImpl_UnpinMessage(t *testing.T) {
6868
t.Run("pin not found", func(t *testing.T) {
6969
t.Parallel()
7070

71-
_, err := repo.PinMessage(uuid.Must(uuid.NewV4()), user.GetID())
71+
_, err := repo.PinMessage(uuid.Must(uuid.NewV7()), user.GetID())
7272
assert.EqualError(t, err, repository.ErrNotFound.Error())
7373
})
7474

repository/gorm/repository_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func mustMakeUser(t *testing.T, repo repository.Repository, userName string) mod
166166
userName = random.AlphaNumeric(32)
167167
}
168168
// パスワード無し・アイコンファイルは実際には存在しないことに注意
169-
u, err := repo.CreateUser(repository.CreateUserArgs{Name: userName, Role: role.User, IconFileID: uuid.Must(uuid.NewV4())})
169+
u, err := repo.CreateUser(repository.CreateUserArgs{Name: userName, Role: role.User, IconFileID: uuid.Must(uuid.NewV7())})
170170
require.NoError(t, err)
171171
return u
172172
}
@@ -211,7 +211,7 @@ func mustAddUserToGroup(t *testing.T, repo repository.Repository, userID, groupI
211211
func mustMakeDummyFile(t *testing.T, repo repository.Repository) *model.FileMeta {
212212
t.Helper()
213213
meta := &model.FileMeta{
214-
ID: uuid.Must(uuid.NewV4()),
214+
ID: uuid.Must(uuid.NewV7()),
215215
Name: "dummy",
216216
Mime: "application/octet-stream",
217217
Size: 10,

repository/gorm/stamp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (r *stampRepository) allStampsExist(ids []uuid.UUID) (ok bool, err error) {
139139
// CreateStamp implements StampRepository interface.
140140
func (r *stampRepository) CreateStamp(args repository.CreateStampArgs) (s *model.Stamp, err error) {
141141
stamp := &model.Stamp{
142-
ID: uuid.Must(uuid.NewV4()),
142+
ID: uuid.Must(uuid.NewV7()),
143143
Name: args.Name,
144144
FileID: args.FileID,
145145
CreatorID: args.CreatorID, // uuid.Nilを許容する

repository/gorm/stamp_palette.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (repo *Repository) CreateStampPalette(name, description string, stamps mode
1818
return nil, repository.ErrNilID
1919
}
2020
stampPalette := &model.StampPalette{
21-
ID: uuid.Must(uuid.NewV4()),
21+
ID: uuid.Must(uuid.NewV7()),
2222
Name: name,
2323
Description: description,
2424
Stamps: stamps,

repository/gorm/stamp_palette_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestRepositoryImpl_UpdateStampPalette(t *testing.T) {
6565
t.Parallel()
6666
assert := assert.New(t)
6767

68-
assert.EqualError(repo.UpdateStampPalette(uuid.Must(uuid.NewV4()), repository.UpdateStampPaletteArgs{}), repository.ErrNotFound.Error())
68+
assert.EqualError(repo.UpdateStampPalette(uuid.Must(uuid.NewV7()), repository.UpdateStampPaletteArgs{}), repository.ErrNotFound.Error())
6969
})
7070

7171
t.Run("no change", func(t *testing.T) {
@@ -112,7 +112,7 @@ func TestRepositoryImpl_GetStampPalette(t *testing.T) {
112112
t.Parallel()
113113
assert := assert.New(t)
114114

115-
_, err := repo.GetStampPalette(uuid.Must(uuid.NewV4()))
115+
_, err := repo.GetStampPalette(uuid.Must(uuid.NewV7()))
116116
assert.EqualError(err, repository.ErrNotFound.Error())
117117
})
118118

@@ -146,7 +146,7 @@ func TestRepositoryImpl_DeleteStampPalette(t *testing.T) {
146146
t.Parallel()
147147
assert := assert.New(t)
148148

149-
assert.EqualError(repo.DeleteStampPalette(uuid.Must(uuid.NewV4())), repository.ErrNotFound.Error())
149+
assert.EqualError(repo.DeleteStampPalette(uuid.Must(uuid.NewV7())), repository.ErrNotFound.Error())
150150
})
151151

152152
t.Run("success", func(t *testing.T) {

0 commit comments

Comments
 (0)