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:
wxiaoguang
2026-07-20 11:42:02 +08:00
committed by GitHub
parent 775e3bdb34
commit fff32e9469
378 changed files with 708 additions and 721 deletions
+3 -3
View File
@@ -8,8 +8,8 @@ import (
"errors"
"time"
"gitea.dev/modelmigration"
"gitea.dev/models/db"
"gitea.dev/models/migrations"
system_model "gitea.dev/models/system"
"gitea.dev/modules/log"
"gitea.dev/modules/setting"
@@ -45,12 +45,12 @@ func migrateWithSetting(ctx context.Context, x db.EngineMigration) error {
return versioned_migration.Migrate(ctx, x)
}
if current, err := migrations.GetCurrentDBVersion(x); err != nil {
if current, err := modelmigration.GetCurrentDBVersion(x); err != nil {
return err
} else if current < 0 {
// execute migrations when the database isn't initialized even if AutoMigration is false
return versioned_migration.Migrate(ctx, x)
} else if expected := migrations.ExpectedDBVersion(); current != expected {
} else if expected := modelmigration.ExpectedDBVersion(); current != expected {
log.Fatal(`"database.AUTO_MIGRATION" is disabled, but current database version %d is not equal to the expected version %d.`+
`You can set "database.AUTO_MIGRATION" to true or migrate manually by running "gitea [--config /path/to/app.ini] migrate"`, current, expected)
}