Backport purgeUnusedDependencies

This commit is contained in:
Guillermo Prandi 2020-03-05 22:47:08 -03:00
parent 3187cb5df5
commit d405da12be
2 changed files with 22 additions and 1 deletions

View File

@ -300,7 +300,10 @@ var migrations = []Migration{
// minor revision and when the actual migration is executed again on the next major upgrade).
// * The function must not rely on data structures that might not be present in the branch
// it is backported to, unless its safe that it will add the column itself.
var backports = []Migration{}
var backports = []Migration{
// v117 -> v117.1
NewMigration("remove dependencies from deleted repositories", purgeUnusedDependencies),
}
// Migrate database to current version
func Migrate(x *xorm.Engine) error {

View File

@ -0,0 +1,18 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package migrations
import (
"xorm.io/xorm"
)
func purgeUnusedDependencies(x *xorm.Engine) error {
if _, err := x.Exec("DELETE FROM issue_dependency WHERE issue_id NOT IN (SELECT id FROM issue)"); err != nil {
return err
}
_, err := x.Exec("DELETE FROM issue_dependency WHERE dependency_id NOT IN (SELECT id FROM issue)")
return err
}