mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Add global lock for migrations to make upgrade more safe with multiple replications (#33706)
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/setting/config"
|
||||
"code.gitea.io/gitea/services/versioned_migration"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
@@ -41,16 +42,16 @@ func InitDBEngine(ctx context.Context) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func migrateWithSetting(x *xorm.Engine) error {
|
||||
func migrateWithSetting(ctx context.Context, x *xorm.Engine) error {
|
||||
if setting.Database.AutoMigration {
|
||||
return migrations.Migrate(x)
|
||||
return versioned_migration.Migrate(ctx, x)
|
||||
}
|
||||
|
||||
if current, err := migrations.GetCurrentDBVersion(x); err != nil {
|
||||
return err
|
||||
} else if current < 0 {
|
||||
// execute migrations when the database isn't initialized even if AutoMigration is false
|
||||
return migrations.Migrate(x)
|
||||
return versioned_migration.Migrate(ctx, x)
|
||||
} else if expected := migrations.ExpectedDBVersion(); 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)
|
||||
|
Reference in New Issue
Block a user