mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 22:13:26 +09:00
refactor(modelmigration): thread context through migration functions (#38758)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -49,15 +49,8 @@ type migration struct {
|
||||
}
|
||||
|
||||
// newMigration creates a new migration
|
||||
func newMigration[T func(base.EngineMigration) error | func(context.Context, base.EngineMigration) error](idNumber int64, desc string, fn T) *migration {
|
||||
m := &migration{idNumber: idNumber, description: desc}
|
||||
var ok bool
|
||||
if m.migrate, ok = any(fn).(func(context.Context, base.EngineMigration) error); !ok {
|
||||
m.migrate = func(ctx context.Context, x base.EngineMigration) error {
|
||||
return any(fn).(func(base.EngineMigration) error)(x)
|
||||
}
|
||||
}
|
||||
return m
|
||||
func newMigration(idNumber int64, desc string, fn func(context.Context, base.EngineMigration) error) *migration {
|
||||
return &migration{idNumber: idNumber, description: desc, migrate: fn}
|
||||
}
|
||||
|
||||
// Migrate executes the migration
|
||||
@@ -72,7 +65,7 @@ type Version struct {
|
||||
}
|
||||
|
||||
// Use noopMigration when there is a migration that has been no-oped
|
||||
var noopMigration = func(_ base.EngineMigration) error { return nil }
|
||||
var noopMigration = func(_ context.Context, _ base.EngineMigration) error { return nil }
|
||||
|
||||
var preparedMigrations []*migration
|
||||
|
||||
|
||||
Reference in New Issue
Block a user