chore(db): introduce db.Session and db.EngineMigration interfaces (#37746)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Copilot
2026-05-18 03:56:39 +08:00
committed by GitHub
parent d9149d8a0a
commit 94e3482d1a
300 changed files with 745 additions and 864 deletions
@@ -28,10 +28,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"xorm.io/xorm"
)
var currentEngine *xorm.Engine
var currentEngine db.EngineMigration
func initMigrationTest(t *testing.T) func() {
testlogger.Init()
@@ -148,7 +147,7 @@ func restoreOldDB(t *testing.T, version string) {
_ = sqlDB.Close()
}
func wrappedMigrate(ctx context.Context, x *xorm.Engine) error {
func wrappedMigrate(ctx context.Context, x db.EngineMigration) error {
currentEngine = x
return migrations.Migrate(ctx, x)
}
@@ -165,7 +164,7 @@ func doMigrationTest(t *testing.T, version string) {
beans, _ := db.NamesToBean()
err = db.InitEngineWithMigration(t.Context(), func(ctx context.Context, x *xorm.Engine) error {
err = db.InitEngineWithMigration(t.Context(), func(ctx context.Context, x db.EngineMigration) error {
currentEngine = x
return migrate_base.RecreateTables(beans...)(x)
})
@@ -173,7 +172,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(ctx context.Context, x *xorm.Engine) error {
err = db.InitEngineWithMigration(t.Context(), func(ctx context.Context, x db.EngineMigration) error {
currentEngine = x
return migrate_base.RecreateTables(beans...)(x)
})