File tree Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -585,6 +585,12 @@ func EnsureUpToDate(x *xorm.Engine) error {
585
585
return nil
586
586
}
587
587
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
+
588
594
// Migrate database to current version
589
595
func Migrate (x * xorm.Engine ) error {
590
596
// Set a new clean the default mapper to GonicMapper as that is the default for Gitea.
Original file line number Diff line number Diff line change @@ -46,14 +46,14 @@ func migrateWithSetting(x *xorm.Engine) error {
46
46
return migrations .Migrate (x )
47
47
}
48
48
49
- if current , err := migrations .GetCurrentDBVersion (x ); err != nil {
49
+ if fresh , err := migrations .IsFreshDB (x ); err != nil {
50
50
return err
51
- } else if current < 0 {
51
+ } else if fresh {
52
52
// execute migrations when the database isn't initialized even if AutoMigration is false
53
53
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"` )
57
57
}
58
58
return nil
59
59
}
Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ import (
12
12
)
13
13
14
14
func checkDBVersion (ctx context.Context , logger log.Logger , autofix bool ) error {
15
- logger .Info ("Expected database version: %d" , migrations .ExpectedVersion ())
16
15
if err := db .InitEngineWithMigration (ctx , migrations .EnsureUpToDate ); err != nil {
17
16
if ! autofix {
18
17
logger .Critical ("Error: %v during ensure up to date" , err )
You can’t perform that action at this time.
0 commit comments