2020-12-02 04:56:04 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-02 04:56:04 +00:00
|
|
|
|
|
|
|
package doctor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-09-19 11:49:59 +00:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2020-12-02 04:56:04 +00:00
|
|
|
"code.gitea.io/gitea/models/migrations"
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
)
|
|
|
|
|
2022-01-19 23:26:57 +00:00
|
|
|
func checkDBVersion(ctx context.Context, logger log.Logger, autofix bool) error {
|
2024-10-27 11:54:35 +00:00
|
|
|
logger.Info("Expected database version: %d", migrations.ExpectedDBVersion())
|
2022-01-19 23:26:57 +00:00
|
|
|
if err := db.InitEngineWithMigration(ctx, migrations.EnsureUpToDate); err != nil {
|
2020-12-02 04:56:04 +00:00
|
|
|
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.")
|
|
|
|
|
2022-01-19 23:26:57 +00:00
|
|
|
err = db.InitEngineWithMigration(ctx, migrations.Migrate)
|
2020-12-02 04:56:04 +00:00
|
|
|
if err != nil {
|
2021-05-10 19:48:23 +00:00
|
|
|
logger.Critical("Error: %v during migration", err)
|
2020-12-02 04:56:04 +00:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Register(&Check{
|
|
|
|
Title: "Check Database Version",
|
|
|
|
Name: "check-db-version",
|
|
|
|
IsDefault: true,
|
|
|
|
Run: checkDBVersion,
|
|
|
|
AbortIfFailed: false,
|
|
|
|
Priority: 2,
|
|
|
|
})
|
|
|
|
}
|