clean unlinked webhook and hook_task

This commit is contained in:
奶爸 2018-06-07 10:49:49 +08:00
parent f9fd6109f4
commit 34a50c8aec
2 changed files with 15 additions and 0 deletions

View File

@ -186,6 +186,8 @@ var migrations = []Migration{
NewMigration("add u2f", addU2FReg),
// v66 -> v67
NewMigration("add login source id column for public_key table", addLoginSourceIDToPublicKeyTable),
// v67 -> v68
NewMigration("clean unlinked webhook and hook_task", cleanUnlinkedWebhookAndHookTasks),
}
// Migrate database to current version

13
models/migrations/v67.go Normal file
View File

@ -0,0 +1,13 @@
// Copyright 2017 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 (
"github.com/go-xorm/xorm"
)
func cleanUnlinkedWebhookAndHookTasks(x *xorm.Engine) error {
_, err := x.Exec(`DELETE FROM webhook WHERE (SELECT COUNT(*) FROM repository WHERE id = webhook.repo_id)=0;DELETE FROM hook_task WHERE (SELECT COUNT(*) FROM repository WHERE id = hook_task.repo_id)=0;`)
return err
}