|
| 1 | +// Copyright 2022 The Gitea Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package migrations |
| 6 | + |
| 7 | +import ( |
| 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 (a *improveActionTableIndicesAction) TableName() string { |
| 30 | + return "action" |
| 31 | +} |
| 32 | + |
| 33 | +// TableIndices implements xorm's TableIndices interface |
| 34 | +func (a *improveActionTableIndicesAction) TableIndices() []*schemas.Index { |
| 35 | + actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType) |
| 36 | + actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted") |
| 37 | + |
| 38 | + repoIndex := schemas.NewIndex("r_c_u_d", schemas.IndexType) |
| 39 | + repoIndex.AddColumn("repo_id", "created_unix", "user_id", "is_deleted") |
| 40 | + |
| 41 | + return []*schemas.Index{actUserIndex, repoIndex} |
| 42 | +} |
| 43 | + |
| 44 | +func improveActionTableIndices(x *xorm.Engine) error { |
| 45 | + { |
| 46 | + type Action struct { |
| 47 | + ID int64 `xorm:"pk autoincr"` |
| 48 | + UserID int64 `xorm:"INDEX"` // Receiver user id. |
| 49 | + OpType int |
| 50 | + ActUserID int64 `xorm:"INDEX"` // Action user id. |
| 51 | + RepoID int64 `xorm:"INDEX"` |
| 52 | + CommentID int64 `xorm:"INDEX"` |
| 53 | + IsDeleted bool `xorm:"INDEX NOT NULL DEFAULT false"` |
| 54 | + RefName string |
| 55 | + IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"` |
| 56 | + Content string `xorm:"TEXT"` |
| 57 | + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` |
| 58 | + } |
| 59 | + if err := x.Sync2(&Action{}); err != nil { |
| 60 | + return err |
| 61 | + } |
| 62 | + if err := x.DropIndexes(&Action{}); err != nil { |
| 63 | + return err |
| 64 | + } |
| 65 | + } |
| 66 | + return x.Sync2(&improveActionTableIndicesAction{}) |
| 67 | +} |
0 commit comments