code.gitea.io/gitea@v1.21.7/models/migrations/v1_17/v218.go (about) 1 // Copyright 2022 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package v1_17 //nolint 5 6 import ( 7 "code.gitea.io/gitea/modules/setting" 8 "code.gitea.io/gitea/modules/timeutil" 9 10 "xorm.io/xorm" 11 "xorm.io/xorm/schemas" 12 ) 13 14 type improveActionTableIndicesAction struct { 15 ID int64 `xorm:"pk autoincr"` 16 UserID int64 // Receiver user id. 17 OpType int 18 ActUserID int64 // Action user id. 19 RepoID int64 20 CommentID int64 `xorm:"INDEX"` 21 IsDeleted bool `xorm:"NOT NULL DEFAULT false"` 22 RefName string 23 IsPrivate bool `xorm:"NOT NULL DEFAULT false"` 24 Content string `xorm:"TEXT"` 25 CreatedUnix timeutil.TimeStamp `xorm:"created"` 26 } 27 28 // TableName sets the name of this table 29 func (*improveActionTableIndicesAction) TableName() string { 30 return "action" 31 } 32 33 // TableIndices implements xorm's TableIndices interface 34 func (*improveActionTableIndicesAction) TableIndices() []*schemas.Index { 35 repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType) 36 repoIndex.AddColumn("repo_id", "user_id", "is_deleted") 37 38 actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType) 39 actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted") 40 indices := []*schemas.Index{actUserIndex, repoIndex} 41 if setting.Database.Type.IsPostgreSQL() { 42 cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType) 43 cudIndex.AddColumn("created_unix", "user_id", "is_deleted") 44 indices = append(indices, cudIndex) 45 } 46 47 return indices 48 } 49 50 func ImproveActionTableIndices(x *xorm.Engine) error { 51 return x.Sync(&improveActionTableIndicesAction{}) 52 }