mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
4 years ago
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||
2 years ago
|
// SPDX-License-Identifier: MIT
|
||
4 years ago
|
|
||
|
package doctor
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
3 years ago
|
"code.gitea.io/gitea/models/db"
|
||
4 years ago
|
"code.gitea.io/gitea/models/migrations"
|
||
|
"code.gitea.io/gitea/modules/log"
|
||
|
)
|
||
|
|
||
3 years ago
|
func checkDBVersion(ctx context.Context, logger log.Logger, autofix bool) error {
|
||
2 years ago
|
logger.Info("Expected database version: %d", migrations.ExpectedVersion())
|
||
3 years ago
|
if err := db.InitEngineWithMigration(ctx, migrations.EnsureUpToDate); err != nil {
|
||
4 years ago
|
if !autofix {
|
||
|
logger.Critical("Error: %v during ensure up to date", err)
|
||
|
return err
|
||
|
}
|
||
|
logger.Warn("Got Error: %v during ensure up to date", err)
|
||
|
logger.Warn("Attempting to migrate to the latest DB version to fix this.")
|
||
|
|
||
3 years ago
|
err = db.InitEngineWithMigration(ctx, migrations.Migrate)
|
||
4 years ago
|
if err != nil {
|
||
4 years ago
|
logger.Critical("Error: %v during migration", err)
|
||
4 years ago
|
}
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func init() {
|
||
|
Register(&Check{
|
||
|
Title: "Check Database Version",
|
||
|
Name: "check-db-version",
|
||
|
IsDefault: true,
|
||
|
Run: checkDBVersion,
|
||
|
AbortIfFailed: false,
|
||
|
Priority: 2,
|
||
|
})
|
||
|
}
|