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
+2 -1
View File
@@ -4,6 +4,7 @@
package v1_16
import (
"context"
"encoding/binary"
"fmt"
@@ -11,7 +12,7 @@ import (
"gitea.dev/modules/json"
)
func UnwrapLDAPSourceCfg(x base.EngineMigration) error {
func UnwrapLDAPSourceCfg(_ context.Context, x base.EngineMigration) error {
jsonUnmarshalHandleDoubleEncode := func(bs []byte, v any) error {
err := json.Unmarshal(bs, v)
if err != nil {
+1 -1
View File
@@ -44,7 +44,7 @@ func Test_UnwrapLDAPSourceCfg(t *testing.T) {
}
// Run the migration
if err := UnwrapLDAPSourceCfg(x); err != nil {
if err := UnwrapLDAPSourceCfg(t.Context(), x); err != nil {
assert.NoError(t, err)
return
}
+2 -1
View File
@@ -4,12 +4,13 @@
package v1_16
import (
"context"
"fmt"
"gitea.dev/modelmigration/base"
)
func AddAgitFlowPullRequest(x base.EngineMigration) error {
func AddAgitFlowPullRequest(_ context.Context, x base.EngineMigration) error {
type PullRequestFlow int
type PullRequest struct {
+3 -1
View File
@@ -4,11 +4,13 @@
package v1_16
import (
"context"
"gitea.dev/modelmigration/base"
"gitea.dev/modules/setting"
)
func AlterIssueAndCommentTextFieldsToLongText(x base.EngineMigration) error {
func AlterIssueAndCommentTextFieldsToLongText(_ context.Context, x base.EngineMigration) error {
sess := x.NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
+3 -1
View File
@@ -4,10 +4,12 @@
package v1_16
import (
"context"
"gitea.dev/modelmigration/base"
)
func RecreateIssueResourceIndexTable(x base.EngineMigration) error {
func RecreateIssueResourceIndexTable(_ context.Context, x base.EngineMigration) error {
type IssueIndex struct {
GroupID int64 `xorm:"pk"`
MaxIndex int64 `xorm:"index"`
+6 -2
View File
@@ -3,9 +3,13 @@
package v1_16
import "gitea.dev/modelmigration/base"
import (
"context"
func AddRepoIDForAttachment(x base.EngineMigration) error {
"gitea.dev/modelmigration/base"
)
func AddRepoIDForAttachment(_ context.Context, x base.EngineMigration) error {
type Attachment struct {
ID int64 `xorm:"pk autoincr"`
UUID string `xorm:"uuid UNIQUE"`
+1 -1
View File
@@ -38,7 +38,7 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
}
// Run the migration
if err := AddRepoIDForAttachment(x); err != nil {
if err := AddRepoIDForAttachment(t.Context(), x); err != nil {
assert.NoError(t, err)
return
}
+2 -1
View File
@@ -4,12 +4,13 @@
package v1_16
import (
"context"
"fmt"
"gitea.dev/modelmigration/base"
)
func AddBranchProtectionUnprotectedFilesColumn(x base.EngineMigration) error {
func AddBranchProtectionUnprotectedFilesColumn(_ context.Context, x base.EngineMigration) error {
type ProtectedBranch struct {
UnprotectedFilePatterns string `xorm:"TEXT"`
}
+2 -1
View File
@@ -4,12 +4,13 @@
package v1_16
import (
"context"
"fmt"
"gitea.dev/modelmigration/base"
)
func AddTableCommitStatusIndex(x base.EngineMigration) error {
func AddTableCommitStatusIndex(_ context.Context, x base.EngineMigration) error {
// CommitStatusIndex represents a table for commit status index
type CommitStatusIndex struct {
ID int64
+1 -1
View File
@@ -29,7 +29,7 @@ func Test_AddTableCommitStatusIndex(t *testing.T) {
defer deferable()
// Run the migration
if err := AddTableCommitStatusIndex(x); err != nil {
if err := AddTableCommitStatusIndex(t.Context(), x); err != nil {
assert.NoError(t, err)
return
}
+2 -1
View File
@@ -4,12 +4,13 @@
package v1_16
import (
"context"
"fmt"
"gitea.dev/modelmigration/base"
)
func AddColorColToProjectBoard(x base.EngineMigration) error {
func AddColorColToProjectBoard(_ context.Context, x base.EngineMigration) error {
type ProjectBoard struct {
Color string `xorm:"VARCHAR(7)"`
}
+6 -2
View File
@@ -3,9 +3,13 @@
package v1_16
import "gitea.dev/modelmigration/base"
import (
"context"
func AddRenamedBranchTable(x base.EngineMigration) error {
"gitea.dev/modelmigration/base"
)
func AddRenamedBranchTable(_ context.Context, x base.EngineMigration) error {
type RenamedBranch struct {
ID int64 `xorm:"pk autoincr"`
RepoID int64 `xorm:"INDEX NOT NULL"`
+2 -1
View File
@@ -4,13 +4,14 @@
package v1_16
import (
"context"
"fmt"
"gitea.dev/modelmigration/base"
"gitea.dev/modules/timeutil"
)
func AddTableIssueContentHistory(x base.EngineMigration) error {
func AddTableIssueContentHistory(_ context.Context, x base.EngineMigration) error {
type IssueContentHistory struct {
ID int64 `xorm:"pk autoincr"`
PosterID int64
+2 -1
View File
@@ -4,12 +4,13 @@
package v1_16
import (
"context"
"fmt"
"gitea.dev/modelmigration/base"
)
func AddTableAppState(x base.EngineMigration) error {
func AddTableAppState(_ context.Context, x base.EngineMigration) error {
type AppState struct {
ID string `xorm:"pk varchar(200)"`
Revision int64
+6 -2
View File
@@ -3,9 +3,13 @@
package v1_16
import "gitea.dev/modelmigration/base"
import (
"context"
func DropTableRemoteVersion(x base.EngineMigration) error {
"gitea.dev/modelmigration/base"
)
func DropTableRemoteVersion(_ context.Context, x base.EngineMigration) error {
// drop the orphaned table introduced in `v199`, now the update checker also uses AppState, do not need this table
_ = x.DropTables("remote_version")
return nil
+2 -1
View File
@@ -4,12 +4,13 @@
package v1_16
import (
"context"
"fmt"
"gitea.dev/modelmigration/base"
)
func CreateUserSettingsTable(x base.EngineMigration) error {
func CreateUserSettingsTable(_ context.Context, x base.EngineMigration) error {
type UserSetting struct {
ID int64 `xorm:"pk autoincr"`
UserID int64 `xorm:"index unique(key_userid)"` // to load all of someone's settings
+6 -2
View File
@@ -3,9 +3,13 @@
package v1_16
import "gitea.dev/modelmigration/base"
import (
"context"
func AddProjectIssueSorting(x base.EngineMigration) error {
"gitea.dev/modelmigration/base"
)
func AddProjectIssueSorting(_ context.Context, x base.EngineMigration) error {
// ProjectIssue saves relation from issue to a project
type ProjectIssue struct {
Sorting int64 `xorm:"NOT NULL DEFAULT 0"`
+6 -2
View File
@@ -3,9 +3,13 @@
package v1_16
import "gitea.dev/modelmigration/base"
import (
"context"
func AddSSHKeyIsVerified(x base.EngineMigration) error {
"gitea.dev/modelmigration/base"
)
func AddSSHKeyIsVerified(_ context.Context, x base.EngineMigration) error {
type PublicKey struct {
Verified bool `xorm:"NOT NULL DEFAULT false"`
}
+5 -3
View File
@@ -4,19 +4,21 @@
package v1_16
import (
"context"
"gitea.dev/modelmigration/base"
"xorm.io/xorm/schemas"
)
func MigrateUserPasswordSalt(x base.EngineMigration) error {
func MigrateUserPasswordSalt(ctx context.Context, x base.EngineMigration) error {
dbType := x.Dialect().URI().DBType
// For SQLITE, the max length doesn't matter.
if dbType == schemas.SQLITE {
return nil
}
if err := base.ModifyColumn(x, "user", &schemas.Column{
if err := base.ModifyColumn(ctx, x, "user", &schemas.Column{
Name: "rands",
SQLType: schemas.SQLType{
Name: "VARCHAR",
@@ -29,7 +31,7 @@ func MigrateUserPasswordSalt(x base.EngineMigration) error {
return err
}
return base.ModifyColumn(x, "user", &schemas.Column{
return base.ModifyColumn(ctx, x, "user", &schemas.Column{
Name: "salt",
SQLType: schemas.SQLType{
Name: "VARCHAR",
+2 -1
View File
@@ -4,12 +4,13 @@
package v1_16
import (
"context"
"fmt"
"gitea.dev/modelmigration/base"
)
func AddAuthorizeColForTeamUnit(x base.EngineMigration) error {
func AddAuthorizeColForTeamUnit(_ context.Context, x base.EngineMigration) error {
type TeamUnit struct {
ID int64 `xorm:"pk autoincr"`
OrgID int64 `xorm:"INDEX"`
+6 -2
View File
@@ -3,9 +3,13 @@
package v1_16
import "gitea.dev/modelmigration/base"
import (
"context"
func AddWebAuthnCred(x base.EngineMigration) error {
"gitea.dev/modelmigration/base"
)
func AddWebAuthnCred(_ context.Context, x base.EngineMigration) error {
// NO-OP Don't migrate here - let v210 do this.
return nil
+6 -2
View File
@@ -3,9 +3,13 @@
package v1_16
import "gitea.dev/modelmigration/base"
import (
"context"
func UseBase32HexForCredIDInWebAuthnCredential(x base.EngineMigration) error {
"gitea.dev/modelmigration/base"
)
func UseBase32HexForCredIDInWebAuthnCredential(_ context.Context, x base.EngineMigration) error {
// noop
return nil
}
+6 -2
View File
@@ -3,9 +3,13 @@
package v1_16
import "gitea.dev/modelmigration/base"
import (
"context"
func IncreaseCredentialIDTo410(x base.EngineMigration) error {
"gitea.dev/modelmigration/base"
)
func IncreaseCredentialIDTo410(_ context.Context, x base.EngineMigration) error {
// no-op
// v208 was completely wrong
// So now we have to no-op again.
+2 -1
View File
@@ -4,6 +4,7 @@
package v1_16
import (
"context"
"encoding/base32"
"fmt"
"strings"
@@ -16,7 +17,7 @@ import (
)
// v208 migration was completely broken
func RemigrateU2FCredentials(x base.EngineMigration) error {
func RemigrateU2FCredentials(_ context.Context, x base.EngineMigration) error {
// Create webauthnCredential table
type webauthnCredential struct {
ID int64 `xorm:"pk autoincr"`
+1 -1
View File
@@ -56,7 +56,7 @@ func Test_RemigrateU2FCredentials(t *testing.T) {
}
// Run the migration
if err := RemigrateU2FCredentials(x); err != nil {
if err := RemigrateU2FCredentials(t.Context(), x); err != nil {
assert.NoError(t, err)
return
}