refactor(modelmigration): thread context through migration functions (#38758)

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Copilot
2026-08-03 08:13:15 +00:00
committed by GitHub
co-authored by wxiaoguang
parent e23fe79e5e
commit ac49dbe1a2
304 changed files with 1070 additions and 449 deletions
+6 -2
View File
@@ -3,9 +3,13 @@
package v1_15
import "gitea.dev/modelmigration/base"
import (
"context"
func AddLFSMirrorColumns(x base.EngineMigration) error {
"gitea.dev/modelmigration/base"
)
func AddLFSMirrorColumns(_ context.Context, x base.EngineMigration) error {
type Mirror struct {
LFS bool `xorm:"lfs_enabled NOT NULL DEFAULT false"`
LFSEndpoint string `xorm:"lfs_endpoint TEXT"`
+4 -2
View File
@@ -4,19 +4,21 @@
package v1_15
import (
"context"
"gitea.dev/modelmigration/base"
"xorm.io/xorm/schemas"
)
func ConvertAvatarURLToText(x base.EngineMigration) error {
func ConvertAvatarURLToText(ctx context.Context, x base.EngineMigration) error {
dbType := x.Dialect().URI().DBType
if dbType == schemas.SQLITE { // For SQLITE, varchar or char will always be represented as TEXT
return nil
}
// Some oauth2 providers may give very long avatar urls (i.e. Google)
return base.ModifyColumn(x, "external_login_user", &schemas.Column{
return base.ModifyColumn(ctx, x, "external_login_user", &schemas.Column{
Name: "avatar_url",
SQLType: schemas.SQLType{
Name: schemas.Text,
+3 -1
View File
@@ -4,6 +4,8 @@
package v1_15
import (
"context"
"gitea.dev/modelmigration/base"
"gitea.dev/modules/json"
"gitea.dev/modules/util"
@@ -11,7 +13,7 @@ import (
"xorm.io/builder"
)
func DeleteMigrationCredentials(x base.EngineMigration) (err error) {
func DeleteMigrationCredentials(_ context.Context, x base.EngineMigration) (err error) {
// Task represents a task
type Task struct {
ID int64
+2 -1
View File
@@ -4,12 +4,13 @@
package v1_15
import (
"context"
"strings"
"gitea.dev/modelmigration/base"
)
func AddPrimaryEmail2EmailAddress(x base.EngineMigration) error {
func AddPrimaryEmail2EmailAddress(_ context.Context, x base.EngineMigration) error {
type User struct {
ID int64 `xorm:"pk autoincr"`
Email string `xorm:"NOT NULL"`
+1 -1
View File
@@ -27,7 +27,7 @@ func Test_AddPrimaryEmail2EmailAddress(t *testing.T) {
}
defer deferable()
err := AddPrimaryEmail2EmailAddress(x)
err := AddPrimaryEmail2EmailAddress(t.Context(), x)
assert.NoError(t, err)
type EmailAddress struct {
+6 -2
View File
@@ -3,9 +3,13 @@
package v1_15
import "gitea.dev/modelmigration/base"
import (
"context"
func AddIssueResourceIndexTable(x base.EngineMigration) error {
"gitea.dev/modelmigration/base"
)
func AddIssueResourceIndexTable(_ context.Context, x base.EngineMigration) error {
type ResourceIndex struct {
GroupID int64 `xorm:"pk"`
MaxIndex int64 `xorm:"index"`
+1 -1
View File
@@ -28,7 +28,7 @@ func Test_AddIssueResourceIndexTable(t *testing.T) {
defer deferable()
// Run the migration
if err := AddIssueResourceIndexTable(x); err != nil {
if err := AddIssueResourceIndexTable(t.Context(), x); err != nil {
assert.NoError(t, err)
return
}
+2 -1
View File
@@ -4,6 +4,7 @@
package v1_15
import (
"context"
"fmt"
"time"
@@ -11,7 +12,7 @@ import (
"gitea.dev/modules/timeutil"
)
func CreatePushMirrorTable(x base.EngineMigration) error {
func CreatePushMirrorTable(_ context.Context, x base.EngineMigration) error {
type PushMirror struct {
ID int64 `xorm:"pk autoincr"`
RepoID int64 `xorm:"INDEX"`
+3 -3
View File
@@ -11,7 +11,7 @@ import (
"gitea.dev/modules/setting"
)
func RenameTaskErrorsToMessage(x base.EngineMigration) error {
func RenameTaskErrorsToMessage(ctx context.Context, x base.EngineMigration) error {
type Task struct {
Errors string `xorm:"TEXT"` // if task failed, saved the error reason
Type int
@@ -19,13 +19,13 @@ func RenameTaskErrorsToMessage(x base.EngineMigration) error {
}
// This migration maybe rerun so that we should check if it has been run
messageExist, err := x.Dialect().IsColumnExist(x.DB(), context.Background(), "task", "message")
messageExist, err := x.Dialect().IsColumnExist(x.DB(), ctx, "task", "message")
if err != nil {
return err
}
if messageExist {
errorsExist, err := x.Dialect().IsColumnExist(x.DB(), context.Background(), "task", "errors")
errorsExist, err := x.Dialect().IsColumnExist(x.DB(), ctx, "task", "errors")
if err != nil {
return err
}
+6 -2
View File
@@ -3,9 +3,13 @@
package v1_15
import "gitea.dev/modelmigration/base"
import (
"context"
func AddRepoArchiver(x base.EngineMigration) error {
"gitea.dev/modelmigration/base"
)
func AddRepoArchiver(_ context.Context, x base.EngineMigration) error {
// RepoArchiver represents all archivers
type RepoArchiver struct {
ID int64 `xorm:"pk autoincr"`
+3 -1
View File
@@ -4,11 +4,13 @@
package v1_15
import (
"context"
"gitea.dev/modelmigration/base"
"gitea.dev/modules/timeutil"
)
func CreateProtectedTagTable(x base.EngineMigration) error {
func CreateProtectedTagTable(_ context.Context, x base.EngineMigration) error {
type ProtectedTag struct {
ID int64 `xorm:"pk autoincr"`
RepoID int64
+3 -1
View File
@@ -4,10 +4,12 @@
package v1_15
import (
"context"
"gitea.dev/modelmigration/base"
)
func DropWebhookColumns(x base.EngineMigration) error {
func DropWebhookColumns(_ context.Context, x base.EngineMigration) error {
// Make sure the columns exist before dropping them
type Webhook struct {
Signature string `xorm:"TEXT"`
+6 -2
View File
@@ -3,9 +3,13 @@
package v1_15
import "gitea.dev/modelmigration/base"
import (
"context"
func AddKeyIsVerified(x base.EngineMigration) error {
"gitea.dev/modelmigration/base"
)
func AddKeyIsVerified(_ context.Context, x base.EngineMigration) error {
type GPGKey struct {
Verified bool `xorm:"NOT NULL DEFAULT false"`
}