diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-09-15 03:41:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-14 20:41:40 +0100 |
commit | e2f0ab3343cd4ed710221d96c253566c20cfab04 (patch) | |
tree | c6fc2022a740e91a3a17cdccdae256dc5733feac /models/attachment.go | |
parent | 87505a9464a2c2c9d16547e06b0c922518dea73c (diff) | |
download | gitea-e2f0ab3343cd4ed710221d96c253566c20cfab04.tar.gz gitea-e2f0ab3343cd4ed710221d96c253566c20cfab04.zip |
Add doctor dbconsistency check for release and attachment (#16978)
Diffstat (limited to 'models/attachment.go')
-rw-r--r-- | models/attachment.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/models/attachment.go b/models/attachment.go index 330e965bb1..96048db00a 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -272,3 +272,16 @@ func IterateAttachment(f func(attach *Attachment) error) error { } } } + +// CountOrphanedAttachments returns the number of bad attachments +func CountOrphanedAttachments() (int64, error) { + return x.Where("(issue_id > 0 and issue_id not in (select id from issue)) or (release_id > 0 and release_id not in (select id from `release`))"). + Count(new(Attachment)) +} + +// DeleteOrphanedAttachments delete all bad attachments +func DeleteOrphanedAttachments() error { + _, err := x.Where("(issue_id > 0 and issue_id not in (select id from issue)) or (release_id > 0 and release_id not in (select id from `release`))"). + Delete(new(Attachment)) + return err +} |