summaryrefslogtreecommitdiffstats
path: root/modules/doctor
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-03-18 06:06:40 +0000
committerGitHub <noreply@github.com>2021-03-18 02:06:40 -0400
commit070c57867d95e4555b5c9ab83a66eb35a3ae2bb4 (patch)
treecfcbeb2423eb5ffa556ac9155ba69a11292a7c94 /modules/doctor
parent71aca93decc10253133dcd77b64dae5d311d7163 (diff)
downloadgitea-070c57867d95e4555b5c9ab83a66eb35a3ae2bb4.tar.gz
gitea-070c57867d95e4555b5c9ab83a66eb35a3ae2bb4.zip
Fix postgres ID sequences broken by recreate-table (#15015)
* Fix postgres ID sequences broken by recreate-table Unfortunately there is a subtle problem with recreatetable on postgres which leads to the sequences not being renamed and not being left at 0. Fix #14725 Signed-off-by: Andrew Thornton <art27@cantab.net> * let us try information_schema instead Signed-off-by: Andrew Thornton <art27@cantab.net> * try again Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'modules/doctor')
-rw-r--r--modules/doctor/dbconsistency.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/modules/doctor/dbconsistency.go b/modules/doctor/dbconsistency.go
index 942a45cb30..1e3c7258e3 100644
--- a/modules/doctor/dbconsistency.go
+++ b/modules/doctor/dbconsistency.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/migrations"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/setting"
)
func checkDBConsistency(logger log.Logger, autofix bool) error {
@@ -131,6 +132,25 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
}
// TODO: function to recalc all counters
+ if setting.Database.UsePostgreSQL {
+ count, err = models.CountBadSequences()
+ if err != nil {
+ logger.Critical("Error: %v whilst checking sequence values")
+ }
+ if count > 0 {
+ if autofix {
+ err := models.FixBadSequences()
+ if err != nil {
+ logger.Critical("Error: %v whilst attempting to fix sequences")
+ return err
+ }
+ logger.Info("%d sequences updated", count)
+ } else {
+ logger.Warn("%d sequences with incorrect values", count)
+ }
+ }
+ }
+
return nil
}