fix lints

This commit is contained in:
qwerty287 2024-07-18 17:25:35 +02:00
parent 5ef3cf4f47
commit e46974d6f5
No known key found for this signature in database
3 changed files with 11 additions and 6 deletions

View File

@ -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.

View File

@ -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
}

View File

@ -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)