1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 10:18:38 +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

@@ -5,6 +5,7 @@ package migrations
import (
"compress/gzip"
"context"
"database/sql"
"fmt"
"io"
@@ -247,7 +248,7 @@ func restoreOldDB(t *testing.T, version string) {
}
}
func wrappedMigrate(x *xorm.Engine) error {
func wrappedMigrate(ctx context.Context, x *xorm.Engine) error {
currentEngine = x
return migrations.Migrate(x)
}
@@ -264,7 +265,7 @@ func doMigrationTest(t *testing.T, version string) {
beans, _ := db.NamesToBean()
err = db.InitEngineWithMigration(t.Context(), func(x *xorm.Engine) error {
err = db.InitEngineWithMigration(t.Context(), func(ctx context.Context, x *xorm.Engine) error {
currentEngine = x
return migrate_base.RecreateTables(beans...)(x)
})
@@ -272,7 +273,7 @@ func doMigrationTest(t *testing.T, version string) {
currentEngine.Close()
// We do this a second time to ensure that there is not a problem with retained indices
err = db.InitEngineWithMigration(t.Context(), func(x *xorm.Engine) error {
err = db.InitEngineWithMigration(t.Context(), func(ctx context.Context, x *xorm.Engine) error {
currentEngine = x
return migrate_base.RecreateTables(beans...)(x)
})