Skip to content

Commit ae452d0

Browse files
sapklunny
andauthored
Migration for deleting orphaned dependencies (#10617)
Co-authored-by: Lunny Xiao <[email protected]>
1 parent 10081f8 commit ae452d0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ var migrations = []Migration{
190190
NewMigration("add repository code language statistics", addLanguageStats),
191191
// v128 -> v129
192192
NewMigration("fix merge base for pull requests", fixMergeBase),
193+
// v129 -> v130
194+
NewMigration("remove dependencies from deleted repositories", purgeUnusedDependencies),
193195
}
194196

195197
// Migrate database to current version

models/migrations/v129.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2020 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+
"xorm.io/xorm"
9+
)
10+
11+
func purgeUnusedDependencies(x *xorm.Engine) error {
12+
13+
if _, err := x.Exec("DELETE FROM issue_dependency WHERE issue_id NOT IN (SELECT id FROM issue)"); err != nil {
14+
return err
15+
}
16+
_, err := x.Exec("DELETE FROM issue_dependency WHERE dependency_id NOT IN (SELECT id FROM issue)")
17+
return err
18+
}

0 commit comments

Comments
 (0)