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 /modules/doctor | |
parent | 87505a9464a2c2c9d16547e06b0c922518dea73c (diff) | |
download | gitea-e2f0ab3343cd4ed710221d96c253566c20cfab04.tar.gz gitea-e2f0ab3343cd4ed710221d96c253566c20cfab04.zip |
Add doctor dbconsistency check for release and attachment (#16978)
Diffstat (limited to 'modules/doctor')
-rw-r--r-- | modules/doctor/dbconsistency.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/modules/doctor/dbconsistency.go b/modules/doctor/dbconsistency.go index 23e8331e77..0d84c63976 100644 --- a/modules/doctor/dbconsistency.go +++ b/modules/doctor/dbconsistency.go @@ -74,6 +74,24 @@ func checkDBConsistency(logger log.Logger, autofix bool) error { } } + // find releases without existing repository + count, err = models.CountOrphanedObjects("release", "repository", "release.repo_id=repository.id") + if err != nil { + logger.Critical("Error: %v whilst counting orphaned objects", err) + return err + } + if count > 0 { + if autofix { + if err = models.DeleteOrphanedObjects("release", "repository", "release.repo_id=repository.id"); err != nil { + logger.Critical("Error: %v whilst deleting orphaned objects", err) + return err + } + logger.Info("%d releases without existing repository deleted", count) + } else { + logger.Warn("%d releases without existing repository", count) + } + } + // find pulls without existing issues count, err = models.CountOrphanedObjects("pull_request", "issue", "pull_request.issue_id=issue.id") if err != nil { @@ -110,6 +128,24 @@ func checkDBConsistency(logger log.Logger, autofix bool) error { } } + // find attachments without existing issues or releases + count, err = models.CountOrphanedAttachments() + if err != nil { + logger.Critical("Error: %v whilst counting orphaned objects", err) + return err + } + if count > 0 { + if autofix { + if err = models.DeleteOrphanedAttachments(); err != nil { + logger.Critical("Error: %v whilst deleting orphaned objects", err) + return err + } + logger.Info("%d attachments without existing issue or release deleted", count) + } else { + logger.Warn("%d attachments without existing issue or release", count) + } + } + // find null archived repositories count, err = models.CountNullArchivedRepository() if err != nil { |