File tree 3 files changed +45
-1
lines changed
3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -227,6 +227,8 @@ var migrations = []Migration{
227
227
NewMigration ("hash application token" , hashAppToken ),
228
228
// v86 -> v87
229
229
NewMigration ("add http method to webhook" , addHTTPMethodToWebhook ),
230
+ // v87 -> v88
231
+ NewMigration ("delete orphaned attachments" , deleteOrphanedAttachments ),
230
232
}
231
233
232
234
// Migrate database to current version
Original file line number Diff line number Diff line change @@ -14,5 +14,4 @@ func addIsLockedToIssues(x *xorm.Engine) error {
14
14
}
15
15
16
16
return x .Sync2 (new (Issue ))
17
-
18
17
}
Original file line number Diff line number Diff line change
1
+ package models
2
+
3
+ import (
4
+ "os"
5
+
6
+ "code.gitea.io/gitea/models"
7
+ "code.gitea.io/gitea/modules/setting"
8
+ "github.com/go-xorm/xorm"
9
+ )
10
+
11
+ func deleteOrphanedAttachments (x * xorm.Engine ) error {
12
+
13
+ type Attachment struct {
14
+ ID int64 `xorm:"pk autoincr"`
15
+ UUID string `xorm:"uuid UNIQUE"`
16
+ IssueID int64 `xorm:"INDEX"`
17
+ ReleaseID int64 `xorm:"INDEX"`
18
+ CommentID int64
19
+ }
20
+
21
+ sess := x .NewSession ()
22
+ defer sess .Close ()
23
+
24
+ err := sess .BufferSize (setting .IterateBufferSize ).
25
+ Where ("comment_id = ? AND release_id = ?" , 0 , 0 ).Cols ("uuid" ).
26
+ Iterate (new (Attachment ),
27
+ func (idx int , bean interface {}) error {
28
+ attachment := bean .(* Attachment )
29
+
30
+ if err := os .RemoveAll (models .AttachmentLocalPath (attachment .UUID )); err != nil {
31
+ return err
32
+ }
33
+
34
+ _ , err := sess .Delete (attachment )
35
+ return err
36
+ })
37
+
38
+ if err != nil {
39
+ return err
40
+ }
41
+
42
+ return sess .Commit ()
43
+ }
You can’t perform that action at this time.
0 commit comments