Skip to content

Commit e46974d

Browse files
committed
fix lints
1 parent 5ef3cf4 commit e46974d

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

models/migrations/migrations.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,12 @@ func EnsureUpToDate(x *xorm.Engine) error {
585585
return nil
586586
}
587587

588+
// EnsureUpToDate will check if the db is completely new
589+
func IsFreshDB(x *xorm.Engine) (bool, error) {
590+
exist, err := x.IsTableExist(&xormigrate.Migration{})
591+
return !exist, err
592+
}
593+
588594
// Migrate database to current version
589595
func Migrate(x *xorm.Engine) error {
590596
// Set a new clean the default mapper to GonicMapper as that is the default for Gitea.

routers/common/db.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ func migrateWithSetting(x *xorm.Engine) error {
4646
return migrations.Migrate(x)
4747
}
4848

49-
if current, err := migrations.GetCurrentDBVersion(x); err != nil {
49+
if fresh, err := migrations.IsFreshDB(x); err != nil {
5050
return err
51-
} else if current < 0 {
51+
} else if fresh {
5252
// execute migrations when the database isn't initialized even if AutoMigration is false
5353
return migrations.Migrate(x)
54-
} else if expected := migrations.ExpectedVersion(); current != expected {
55-
log.Fatal(`"database.AUTO_MIGRATION" is disabled, but current database version %d is not equal to the expected version %d.`+
56-
`You can set "database.AUTO_MIGRATION" to true or migrate manually by running "gitea [--config /path/to/app.ini] migrate"`, current, expected)
54+
} else if upToDate := migrations.EnsureUpToDate(x); upToDate != nil {
55+
log.Fatal(`"database.AUTO_MIGRATION" is disabled, but current database misses migrations.` +
56+
`You can set "database.AUTO_MIGRATION" to true or migrate manually by running "gitea [--config /path/to/app.ini] migrate"`)
5757
}
5858
return nil
5959
}

services/doctor/dbversion.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
)
1313

1414
func checkDBVersion(ctx context.Context, logger log.Logger, autofix bool) error {
15-
logger.Info("Expected database version: %d", migrations.ExpectedVersion())
1615
if err := db.InitEngineWithMigration(ctx, migrations.EnsureUpToDate); err != nil {
1716
if !autofix {
1817
logger.Critical("Error: %v during ensure up to date", err)

0 commit comments

Comments
 (0)