diff options
Diffstat (limited to 'models/consistency.go')
-rw-r--r-- | models/consistency.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/models/consistency.go b/models/consistency.go index bed94d9395..9d76d26bbb 100644 --- a/models/consistency.go +++ b/models/consistency.go @@ -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"). |