@@ -8,34 +8,68 @@ import (
88 "code.gitea.io/gitea/modules/timeutil"
99
1010 "xorm.io/xorm"
11+ "xorm.io/xorm/schemas"
1112)
1213
13- func AddFileStatusToAttachment (x * xorm.Engine ) error {
14- type Attachment struct {
15- ID int64 `xorm:"pk autoincr"`
16- UUID string `xorm:"uuid UNIQUE"`
17- RepoID int64 `xorm:"INDEX"` // this should not be zero
18- IssueID int64 `xorm:"INDEX"` // maybe zero when creating
19- ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
20- UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
21- CommentID int64 `xorm:"INDEX"`
22- Name string
23- DownloadCount int64 `xorm:"DEFAULT 0"`
24- Status db.FileStatus `xorm:"INDEX DEFAULT 0"`
25- DeleteFailedCount int `xorm:"DEFAULT 0"` // Number of times the deletion failed, used to prevent infinite loop
26- LastDeleteFailedTime timeutil.TimeStamp // Last time the deletion failed, used to prevent infinite loop
27- Size int64 `xorm:"DEFAULT 0"`
28- CreatedUnix timeutil.TimeStamp `xorm:"created"`
29- CustomDownloadURL string `xorm:"-"`
30- }
14+ type Attachment321 struct {
15+ ID int64 `xorm:"pk autoincr"`
16+ UUID string `xorm:"uuid UNIQUE"`
17+ RepoID int64 `xorm:"INDEX"` // this should not be zero
18+ IssueID int64 `xorm:"INDEX"` // maybe zero when creating
19+ ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
20+ UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
21+ CommentID int64 `xorm:"INDEX"`
22+ Name string
23+ DownloadCount int64 `xorm:"DEFAULT 0"`
24+ Status db.FileStatus `xorm:"INDEX DEFAULT 1 NOT NULL"` // 1 = normal, 2 = to be deleted
25+ DeleteFailedCount int `xorm:"DEFAULT 0"` // Number of times the deletion failed, used to prevent infinite loop
26+ LastDeleteFailedTime timeutil.TimeStamp // Last time the deletion failed, used to prevent infinite loop
27+ Size int64 `xorm:"DEFAULT 0"`
28+ CreatedUnix timeutil.TimeStamp `xorm:"created"`
29+ }
3130
32- if err := x .Sync (new (Attachment )); err != nil {
33- return err
34- }
31+ func (a * Attachment321 ) TableName () string {
32+ return "attachment"
33+ }
34+
35+ // TableIndices implements xorm's TableIndices interface
36+ func (a * Attachment321 ) TableIndices () []* schemas.Index {
37+ uuidIndex := schemas .NewIndex ("attachment_uuid" , schemas .UniqueType )
38+ uuidIndex .AddColumn ("uuid" )
39+
40+ repoIndex := schemas .NewIndex ("attachment_repo_id" , schemas .IndexType )
41+ repoIndex .AddColumn ("repo_id" )
42+
43+ issueIndex := schemas .NewIndex ("attachment_issue_id" , schemas .IndexType )
44+ issueIndex .AddColumn ("issue_id" )
3545
36- if _ , err := x .Exec ("UPDATE `attachment` SET status = ? WHERE status IS NULL" , db .FileStatusNormal ); err != nil {
37- return err
46+ releaseIndex := schemas .NewIndex ("attachment_release_id" , schemas .IndexType )
47+ releaseIndex .AddColumn ("release_id" )
48+
49+ uploaderIndex := schemas .NewIndex ("attachment_uploader_id" , schemas .IndexType )
50+ uploaderIndex .AddColumn ("uploader_id" )
51+
52+ commentIndex := schemas .NewIndex ("attachment_comment_id" , schemas .IndexType )
53+ commentIndex .AddColumn ("comment_id" )
54+
55+ statusIndex := schemas .NewIndex ("attachment_status" , schemas .IndexType )
56+ statusIndex .AddColumn ("status" )
57+
58+ statusIDIndex := schemas .NewIndex ("attachment_status_id" , schemas .IndexType )
59+ statusIDIndex .AddColumn ("status_id" , "id" ) // For status = ? AND id > ? query
60+
61+ return []* schemas.Index {
62+ uuidIndex ,
63+ repoIndex ,
64+ issueIndex ,
65+ releaseIndex ,
66+ uploaderIndex ,
67+ commentIndex ,
68+ statusIndex ,
69+ statusIDIndex ,
3870 }
71+ }
3972
40- return nil
73+ func AddFileStatusToAttachment (x * xorm.Engine ) error {
74+ return x .Sync (new (Attachment321 ))
4175}
0 commit comments