summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-05-29 17:41:23 +0200
committerGitHub <noreply@github.com>2020-05-29 16:41:23 +0100
commit801f4b9e7a49fb6366efbb1bc6fcb31c5f7b8fcc (patch)
treef0864cf1d828dfd306bd1bdd6e270449a2d275ea
parentc0c3a533a071d80a0509ea6dd4adf5c10f2ceb48 (diff)
downloadgitea-801f4b9e7a49fb6366efbb1bc6fcb31c5f7b8fcc.tar.gz
gitea-801f4b9e7a49fb6366efbb1bc6fcb31c5f7b8fcc.zip
Add tracked time fix to doctor (part of #11111) (#11138)
Backports the tracked-time fix from #11111 (part of #11111) Fixes tracked time errors following repo deletion (#10280) and adds the fix to the default doctor tasks
-rw-r--r--cmd/doctor.go46
1 files changed, 45 insertions, 1 deletions
diff --git a/cmd/doctor.go b/cmd/doctor.go
index 61ca27cf3f..2ffdfdc5f7 100644
--- a/cmd/doctor.go
+++ b/cmd/doctor.go
@@ -84,7 +84,7 @@ var checklist = []check{
},
{
title: "Check Database Version",
- name: "check-db",
+ name: "check-db-version",
isDefault: true,
f: runDoctorCheckDBVersion,
abortIfFailed: true,
@@ -113,6 +113,12 @@ var checklist = []check{
isDefault: false,
f: runDoctorPRMergeBase,
},
+ {
+ title: "Check consistency of database",
+ name: "check-db-consistency",
+ isDefault: true,
+ f: runDoctorCheckDBConsistency,
+ },
// more checks please append here
}
@@ -494,3 +500,41 @@ func runDoctorScriptType(ctx *cli.Context) ([]string, error) {
}
return []string{fmt.Sprintf("ScriptType %s is on the current PATH at %s", setting.ScriptType, path)}, nil
}
+
+func runDoctorCheckDBConsistency(ctx *cli.Context) ([]string, error) {
+ _, committer, err := models.TxDBContext()
+ if err != nil {
+ return nil, err
+ }
+ sess := committer.(models.Engine)
+ defer committer.Close()
+ var results []string
+
+ //find tracked times without existing issues/pulls
+ count, err := sess.Table("tracked_time").
+ Join("LEFT", "issue", "tracked_time.issue_id=issue.id").
+ Where("issue.id is NULL").
+ Count("id")
+ if err != nil {
+ return nil, err
+ }
+ if count > 0 {
+ if ctx.Bool("fix") {
+ if _, err = sess.In("id", builder.Select("tracked_time.id").
+ From("tracked_time").
+ Join("LEFT", "issue", "tracked_time.issue_id=issue.id").
+ Where(builder.IsNull{"issue.id"})).
+ Delete(models.TrackedTime{}); err != nil {
+ return nil, err
+ }
+ results = append(results, fmt.Sprintf("%d tracked times without existing issue deleted", count))
+ } else {
+ results = append(results, fmt.Sprintf("%d tracked times without existing issue", count))
+ }
+ }
+
+ if ctx.Bool("fix") {
+ return results, committer.Commit()
+ }
+ return results, nil
+}