1
1
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:
Lunny Xiao
2025-03-07 13:08:53 -08:00
committed by GitHub
parent b8c2afdc5f
commit 1b2dffff8e
10 changed files with 46 additions and 18 deletions

View File

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