From 033abbf80569719f8dde2dd62624816eeaec6e64 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Thu, 29 Apr 2021 00:16:00 +0200 Subject: [PATCH 1/3] Added missing error parameters. --- modules/doctor/dbconsistency.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/doctor/dbconsistency.go b/modules/doctor/dbconsistency.go index 8c960cb4a8bde..a0d89318fb58b 100644 --- a/modules/doctor/dbconsistency.go +++ b/modules/doctor/dbconsistency.go @@ -29,7 +29,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error { if count > 0 { if autofix { if err = models.DeleteOrphanedLabels(); err != nil { - logger.Critical("Error: %v whilst deleting orphaned labels") + logger.Critical("Error: %v whilst deleting orphaned labels", err) return err } logger.Info("%d labels without existing repository/organisation deleted", count) @@ -47,7 +47,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error { if count > 0 { if autofix { if err = models.DeleteOrphanedIssueLabels(); err != nil { - logger.Critical("Error: %v whilst deleting orphaned issue_labels") + logger.Critical("Error: %v whilst deleting orphaned issue_labels", err) return err } logger.Info("%d issue_labels without existing label deleted", count) @@ -65,7 +65,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error { if count > 0 { if autofix { if err = models.DeleteOrphanedIssues(); err != nil { - logger.Critical("Error: %v whilst deleting orphaned issues") + logger.Critical("Error: %v whilst deleting orphaned issues", err) return err } logger.Info("%d issues without existing repository deleted", count) @@ -83,7 +83,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error { if count > 0 { if autofix { if err = models.DeleteOrphanedObjects("pull_request", "issue", "pull_request.issue_id=issue.id"); err != nil { - logger.Critical("Error: %v whilst deleting orphaned objects") + logger.Critical("Error: %v whilst deleting orphaned objects", err) return err } logger.Info("%d pull requests without existing issue deleted", count) @@ -101,7 +101,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error { if count > 0 { if autofix { if err = models.DeleteOrphanedObjects("tracked_time", "issue", "tracked_time.issue_id=issue.id"); err != nil { - logger.Critical("Error: %v whilst deleting orphaned objects") + logger.Critical("Error: %v whilst deleting orphaned objects", err) return err } logger.Info("%d tracked times without existing issue deleted", count) @@ -120,7 +120,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error { if autofix { updatedCount, err := models.FixNullArchivedRepository() if err != nil { - logger.Critical("Error: %v whilst fixing null archived repositories") + logger.Critical("Error: %v whilst fixing null archived repositories", err) return err } logger.Info("%d repositories with null is_archived updated", updatedCount) @@ -139,7 +139,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error { if autofix { updatedCount, err := models.FixCommentTypeLabelWithEmptyLabel() if err != nil { - logger.Critical("Error: %v whilst removing label comments with empty labels") + logger.Critical("Error: %v whilst removing label comments with empty labels", err) return err } logger.Info("%d label comments with empty labels removed", updatedCount) @@ -197,7 +197,7 @@ func checkDBConsistency(logger log.Logger, autofix bool) error { if autofix { err := models.FixBadSequences() if err != nil { - logger.Critical("Error: %v whilst attempting to fix sequences") + logger.Critical("Error: %v whilst attempting to fix sequences", err) return err } logger.Info("%d sequences updated", count) From b2b3002e78875e4aa2e35ef6c89125e4ffe160bc Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Thu, 29 Apr 2021 00:16:30 +0200 Subject: [PATCH 2/3] Delete protected branch if repository gets removed. --- models/repo.go | 1 + 1 file changed, 1 insertion(+) diff --git a/models/repo.go b/models/repo.go index cea874769d128..0a0f725f09d91 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1472,6 +1472,7 @@ func DeleteRepository(doer *User, uid, repoID int64) error { &LanguageStat{RepoID: repoID}, &Comment{RefRepoID: repoID}, &Task{RepoID: repoID}, + &ProtectedBranch{RepoID: repoID}, ); err != nil { return fmt.Errorf("deleteBeans: %v", err) } From e5ed9a7a90308905db7cd5b1a9fe1db27d542480 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Thu, 29 Apr 2021 00:18:00 +0200 Subject: [PATCH 3/3] Added doctor fix. --- modules/doctor/dbconsistency.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/doctor/dbconsistency.go b/modules/doctor/dbconsistency.go index a0d89318fb58b..417a7d4b6b45c 100644 --- a/modules/doctor/dbconsistency.go +++ b/modules/doctor/dbconsistency.go @@ -207,6 +207,24 @@ func checkDBConsistency(logger log.Logger, autofix bool) error { } } + // find protected branches without existing repository + count, err = models.CountOrphanedObjects("protected_branch", "repository", "protected_branch.repo_id=repository.id") + if err != nil { + logger.Critical("Error: %v whilst counting orphaned objects") + return err + } + if count > 0 { + if autofix { + if err = models.DeleteOrphanedObjects("protected_branch", "repository", "protected_branch.repo_id=repository.id"); err != nil { + logger.Critical("Error: %v whilst deleting orphaned objects", err) + return err + } + logger.Info("%d protected branches without existing repository deleted", count) + } else { + logger.Warn("%d protected branches without existing repository", count) + } + } + return nil }