refactor: clean up git repo and model migration packages (#38564)

enable the golangci depguard lint rule: deny "models" and its sub
packages in "modelmigration" package.
This commit is contained in:
wxiaoguang
2026-07-23 01:22:26 +00:00
committed by GitHub
parent fa64b4627a
commit 1acf93d854
43 changed files with 243 additions and 167 deletions
+6 -7
View File
@@ -11,19 +11,14 @@ import (
"regexp"
"strings"
"gitea.dev/models/db"
"gitea.dev/models/db" //nolint:depguard // allow to access db in migration
"gitea.dev/modules/log"
"gitea.dev/modules/setting"
"xorm.io/builder"
"xorm.io/xorm/schemas"
)
// Migrations should never use model structs directly, because the model structs can be different in different releases.
// e.g. if one migration uses "User" model, it works in the early releases, then one day,
// when the User model changes, the migration breaks because it will use the new (incorrect) User model,
// it should only use the old User model. The same to "modules/structs".
// However, many the existing migrations already abuses "modules/structs" (search "gitea.dev/models/" in the migrations).
// TODO: need to fully decouple the migration package and models & structs package
type (
EngineMigration = db.EngineMigration
Session = db.Session
@@ -519,3 +514,7 @@ func ModifyColumn(x EngineMigration, tableName string, col *schemas.Column) erro
}
return nil
}
func Iterate[Bean any](ctx context.Context, cond builder.Cond, f func(ctx context.Context, bean *Bean) error) error {
return db.Iterate(ctx, cond, f)
}