Skip to content

Commit 39a90ea

Browse files
committed
feat: add migration
1 parent 8a4c2ea commit 39a90ea

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

models/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ func prepareMigrationTasks() []*migration {
364364
newMigration(304, "Add index for release sha1", v1_23.AddIndexForReleaseSha1),
365365
newMigration(305, "Add Repository Licenses", v1_23.AddRepositoryLicenses),
366366
newMigration(306, "Add BlockAdminMergeOverride to ProtectedBranch", v1_23.AddBlockAdminMergeOverrideBranchProtection),
367+
newMigration(307, "Improve Notification table indices", v1_23.ImproveNotificationTableIndices),
367368
}
368369
return preparedMigrations
369370
}

models/migrations/v1_23/v307.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import (
7+
issues_model "code.gitea.io/gitea/models/issues"
8+
repo_model "code.gitea.io/gitea/models/repo"
9+
user_model "code.gitea.io/gitea/models/user"
10+
"code.gitea.io/gitea/modules/timeutil"
11+
12+
"xorm.io/xorm"
13+
"xorm.io/xorm/schemas"
14+
)
15+
16+
type (
17+
// NotificationStatus is the status of the notification (read or unread)
18+
NotificationStatus uint8
19+
// NotificationSource is the source of the notification (issue, PR, commit, etc)
20+
NotificationSource uint8
21+
)
22+
23+
type improveNotificationTableIndicesAction struct {
24+
ID int64 `xorm:"pk autoincr"`
25+
UserID int64 `xorm:"INDEX NOT NULL"`
26+
RepoID int64 `xorm:"INDEX NOT NULL"`
27+
28+
Status NotificationStatus `xorm:"SMALLINT INDEX NOT NULL"`
29+
Source NotificationSource `xorm:"SMALLINT INDEX NOT NULL"`
30+
31+
IssueID int64 `xorm:"INDEX NOT NULL"`
32+
CommitID string `xorm:"INDEX"`
33+
CommentID int64
34+
35+
UpdatedBy int64 `xorm:"INDEX NOT NULL"`
36+
37+
Issue *issues_model.Issue `xorm:"-"`
38+
Repository *repo_model.Repository `xorm:"-"`
39+
Comment *issues_model.Comment `xorm:"-"`
40+
User *user_model.User `xorm:"-"`
41+
42+
CreatedUnix timeutil.TimeStamp `xorm:"created INDEX NOT NULL"`
43+
UpdatedUnix timeutil.TimeStamp `xorm:"updated INDEX NOT NULL"`
44+
}
45+
46+
// TableName sets the name of this table
47+
func (*improveNotificationTableIndicesAction) TableName() string {
48+
return "notification"
49+
}
50+
51+
// TableIndices implements xorm's TableIndices interface
52+
func (*improveNotificationTableIndicesAction) TableIndices() []*schemas.Index {
53+
usuuIndex := schemas.NewIndex("u_s_uu", schemas.IndexType)
54+
usuuIndex.AddColumn("user_id", "status", "updated_unix")
55+
indices := []*schemas.Index{usuuIndex}
56+
57+
return indices
58+
}
59+
60+
func ImproveNotificationTableIndices(x *xorm.Engine) error {
61+
return x.Sync(&improveNotificationTableIndicesAction{})
62+
}

0 commit comments

Comments
 (0)