mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-29 00:59:39 +09:00
refactor: prepare to decouple the "model migration" package and "models" package (#38533)
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". --------- Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
@@ -6,11 +6,11 @@ package doctor
|
||||
import (
|
||||
"context"
|
||||
|
||||
modelmigration "gitea.dev/modelmigration"
|
||||
actions_model "gitea.dev/models/actions"
|
||||
activities_model "gitea.dev/models/activities"
|
||||
"gitea.dev/models/db"
|
||||
issues_model "gitea.dev/models/issues"
|
||||
"gitea.dev/models/migrations"
|
||||
repo_model "gitea.dev/models/repo"
|
||||
secret_model "gitea.dev/models/secret"
|
||||
"gitea.dev/modules/log"
|
||||
@@ -249,7 +249,7 @@ func prepareDBConsistencyChecks() []consistencyCheck {
|
||||
|
||||
func checkDBConsistency(ctx context.Context, logger log.Logger, autofix bool) error {
|
||||
// make sure DB version is uptodate
|
||||
if err := db.InitEngineWithMigration(ctx, migrations.EnsureUpToDate); err != nil {
|
||||
if err := db.InitEngineWithMigration(ctx, modelmigration.EnsureUpToDate); err != nil {
|
||||
logger.Critical("Model version on the database does not match the current Gitea version. Model consistency will not be checked until the database is upgraded")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ package versioned_migration
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration"
|
||||
"gitea.dev/models/db"
|
||||
"gitea.dev/models/migrations"
|
||||
"gitea.dev/modules/globallock"
|
||||
)
|
||||
|
||||
@@ -19,5 +19,5 @@ func Migrate(ctx context.Context, x db.EngineMigration) error {
|
||||
}
|
||||
defer release()
|
||||
|
||||
return migrations.Migrate(ctx, x)
|
||||
return modelmigration.Migrate(ctx, x)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user