| 
 | 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