refactor: use WithRepo instead of WithDir for most git operations, clean up model migrations (#38555)

by the way, remove some unnecessary "models" imports from model
migration package, fix migration test model init bug
(modelmigration/migrationtest/tests.go)
This commit is contained in:
wxiaoguang
2026-07-21 12:18:00 +00:00
committed by GitHub
parent 8731ea4bbb
commit 91eb14c944
45 changed files with 211 additions and 217 deletions
+4
View File
@@ -116,6 +116,10 @@ func RegisterModel(bean any, initFunc ...func() error) {
}
}
func ResetModels() {
registeredModels, registeredInitFuncs = nil, nil
}
// SyncAllTables sync the schemas of all tables, is required by unit test code
func SyncAllTables() error {
_, err := xormEngine.StoreEngine("InnoDB").SyncWithOptions(xorm.SyncOptions{
+15
View File
@@ -0,0 +1,15 @@
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package models
import (
"context"
"gitea.dev/models/unit"
)
// Init initialize model
func Init(ctx context.Context) error {
return unit.LoadUnitConfig()
}
@@ -1,7 +1,7 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package models
package repostats
import (
"testing"
+1 -7
View File
@@ -2,7 +2,7 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package models
package repostats
import (
"context"
@@ -12,7 +12,6 @@ import (
"gitea.dev/models/db"
issues_model "gitea.dev/models/issues"
repo_model "gitea.dev/models/repo"
"gitea.dev/models/unit"
user_model "gitea.dev/models/user"
"gitea.dev/modules/log"
@@ -21,11 +20,6 @@ import (
"xorm.io/builder"
)
// Init initialize model
func Init(ctx context.Context) error {
return unit.LoadUnitConfig()
}
type repoChecker struct {
querySQL func(ctx context.Context) ([]int64, error)
correctSQL func(ctx context.Context, id int64) error
@@ -1,7 +1,7 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package models
package repostats
import (
"testing"