mirror of
https://github.com/go-gitea/gitea.git
synced 2024-09-01 14:56:30 +00:00
fix lints
This commit is contained in:
parent
5ef3cf4f47
commit
e46974d6f5
@ -585,6 +585,12 @@ func EnsureUpToDate(x *xorm.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnsureUpToDate will check if the db is completely new
|
||||
func IsFreshDB(x *xorm.Engine) (bool, error) {
|
||||
exist, err := x.IsTableExist(&xormigrate.Migration{})
|
||||
return !exist, err
|
||||
}
|
||||
|
||||
// Migrate database to current version
|
||||
func Migrate(x *xorm.Engine) error {
|
||||
// Set a new clean the default mapper to GonicMapper as that is the default for Gitea.
|
||||
|
@ -46,14 +46,14 @@ func migrateWithSetting(x *xorm.Engine) error {
|
||||
return migrations.Migrate(x)
|
||||
}
|
||||
|
||||
if current, err := migrations.GetCurrentDBVersion(x); err != nil {
|
||||
if fresh, err := migrations.IsFreshDB(x); err != nil {
|
||||
return err
|
||||
} else if current < 0 {
|
||||
} else if fresh {
|
||||
// execute migrations when the database isn't initialized even if AutoMigration is false
|
||||
return migrations.Migrate(x)
|
||||
} else if expected := migrations.ExpectedVersion(); current != expected {
|
||||
log.Fatal(`"database.AUTO_MIGRATION" is disabled, but current database version %d is not equal to the expected version %d.`+
|
||||
`You can set "database.AUTO_MIGRATION" to true or migrate manually by running "gitea [--config /path/to/app.ini] migrate"`, current, expected)
|
||||
} else if upToDate := migrations.EnsureUpToDate(x); upToDate != nil {
|
||||
log.Fatal(`"database.AUTO_MIGRATION" is disabled, but current database misses migrations.` +
|
||||
`You can set "database.AUTO_MIGRATION" to true or migrate manually by running "gitea [--config /path/to/app.ini] migrate"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
)
|
||||
|
||||
func checkDBVersion(ctx context.Context, logger log.Logger, autofix bool) error {
|
||||
logger.Info("Expected database version: %d", migrations.ExpectedVersion())
|
||||
if err := db.InitEngineWithMigration(ctx, migrations.EnsureUpToDate); err != nil {
|
||||
if !autofix {
|
||||
logger.Critical("Error: %v during ensure up to date", err)
|
||||
|
Loading…
Reference in New Issue
Block a user