forked from forgejo/forgejo
Delete Labels & IssueLabels on Repo Delete too (#15039)
* Doctor: find IssueLabels without existing label * on Repo Delete: delete labels & issue_labels too * performance nits * Add Migration: Delete orphaned IssueLabels * Migration v174: use Sync2 * USE sess !!! * better func name * code format & comment * RAW SQL * Update models/migrations/v176.go * next try?
This commit is contained in:
parent
dace0ce1b1
commit
a3a65137ba
7 changed files with 116 additions and 9 deletions
|
@ -224,6 +224,23 @@ func DeleteOrphanedLabels() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// CountOrphanedIssueLabels return count of IssueLabels witch have no label behind anymore
|
||||
func CountOrphanedIssueLabels() (int64, error) {
|
||||
return x.Table("issue_label").
|
||||
Join("LEFT", "label", "issue_label.label_id = label.id").
|
||||
Where(builder.IsNull{"label.id"}).Count()
|
||||
}
|
||||
|
||||
// DeleteOrphanedIssueLabels delete IssueLabels witch have no label behind anymore
|
||||
func DeleteOrphanedIssueLabels() error {
|
||||
_, err := x.In("id", builder.Select("issue_label.id").From("issue_label").
|
||||
Join("LEFT", "label", "issue_label.label_id = label.id").
|
||||
Where(builder.IsNull{"label.id"})).
|
||||
Delete(IssueLabel{})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// CountOrphanedIssues count issues without a repo
|
||||
func CountOrphanedIssues() (int64, error) {
|
||||
return x.Table("issue").
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue