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
+3 -1
View File
@@ -4,12 +4,14 @@
package v1_26
import (
"context"
"gitea.dev/modelmigration/base"
"xorm.io/xorm"
)
func AddActionsConcurrency(x base.EngineMigration) error {
func AddActionsConcurrency(_ context.Context, x base.EngineMigration) error {
type ActionRun struct {
RepoID int64 `xorm:"index(repo_concurrency)"`
RawConcurrency string
+2 -1
View File
@@ -4,12 +4,13 @@
package v1_26
import (
"context"
"fmt"
"gitea.dev/modelmigration/base"
)
func FixClosedMilestoneCompleteness(x base.EngineMigration) error {
func FixClosedMilestoneCompleteness(_ context.Context, x base.EngineMigration) error {
// Update all milestones to recalculate completeness with the new logic:
// - Closed milestones with 0 issues should show 100%
// - All other milestones should calculate based on closed/total ratio
+6 -2
View File
@@ -3,9 +3,13 @@
package v1_26
import "gitea.dev/modelmigration/base"
import (
"context"
func FixMissedRepoIDWhenMigrateAttachments(x base.EngineMigration) error {
"gitea.dev/modelmigration/base"
)
func FixMissedRepoIDWhenMigrateAttachments(_ context.Context, x base.EngineMigration) error {
_, err := x.Exec("UPDATE `attachment` SET `repo_id` = (SELECT `repo_id` FROM `issue` WHERE `issue`.`id` = `attachment`.`issue_id`) WHERE `issue_id` > 0 AND (`repo_id` IS NULL OR `repo_id` = 0);")
if err != nil {
return err
+1 -1
View File
@@ -41,5 +41,5 @@ func Test_FixMissedRepoIDWhenMigrateAttachments(t *testing.T) {
x, deferrable := migrationtest.PrepareTestEnv(t, 0, new(Attachment), new(Issue), new(Release))
defer deferrable()
require.NoError(t, FixMissedRepoIDWhenMigrateAttachments(x))
require.NoError(t, FixMissedRepoIDWhenMigrateAttachments(t.Context(), x))
}
+2 -1
View File
@@ -4,6 +4,7 @@
package v1_26
import (
"context"
"errors"
"fmt"
"net/url"
@@ -91,7 +92,7 @@ type commitSHAAndRuns struct {
// Only rows whose resolved run ID is below legacyURLIDThreshold are rewritten.
// This is because smaller legacy run indexes are more likely to collide with run ID URLs during runtime resolution,
// so this migration prioritizes that lower range and leaves the remaining legacy target URLs to the web compatibility logic.
func FixCommitStatusTargetURLToUseRunAndJobID(x base.EngineMigration) error {
func FixCommitStatusTargetURLToUseRunAndJobID(_ context.Context, x base.EngineMigration) error {
jobsByRunIDCache := make(map[int64][]int64)
repoLinkCache := make(map[int64]string)
groups, err := loadLegacyMigrationRunGroups(x)
+1 -1
View File
@@ -62,7 +62,7 @@ func Test_FixCommitStatusTargetURLToUseRunAndJobID(t *testing.T) {
)
defer deferable()
require.NoError(t, FixCommitStatusTargetURLToUseRunAndJobID(x))
require.NoError(t, FixCommitStatusTargetURLToUseRunAndJobID(t.Context(), x))
cases := []struct {
table string
+3 -1
View File
@@ -4,12 +4,14 @@
package v1_26
import (
"context"
"gitea.dev/modelmigration/base"
"xorm.io/xorm"
)
func AddDisabledToActionRunner(x base.EngineMigration) error {
func AddDisabledToActionRunner(_ context.Context, x base.EngineMigration) error {
type ActionRunner struct {
IsDisabled bool `xorm:"is_disabled NOT NULL DEFAULT false"`
}
+1 -1
View File
@@ -23,7 +23,7 @@ func Test_AddDisabledToActionRunner(t *testing.T) {
_, err := x.Insert(&ActionRunner{Name: "runner"})
require.NoError(t, err)
require.NoError(t, AddDisabledToActionRunner(x))
require.NoError(t, AddDisabledToActionRunner(t.Context(), x))
var isDisabled bool
has, err := x.SQL("SELECT is_disabled FROM action_runner WHERE id = ?", 1).Get(&isDisabled)
+3 -1
View File
@@ -4,12 +4,14 @@
package v1_26
import (
"context"
"gitea.dev/modelmigration/base"
"xorm.io/xorm"
)
func AddTokenPermissionsToActionRunJob(x base.EngineMigration) error {
func AddTokenPermissionsToActionRunJob(_ context.Context, x base.EngineMigration) error {
type ActionRunJob struct {
TokenPermissions string `xorm:"JSON TEXT"`
}
+2 -1
View File
@@ -4,6 +4,7 @@
package v1_26
import (
"context"
"fmt"
"gitea.dev/modelmigration/base"
@@ -28,7 +29,7 @@ func (n *UserBadge) TableIndices() []*schemas.Index {
// AddUniqueIndexForUserBadge adds a compound unique indexes for user badge table
// and it replaces an old index on user_id
func AddUniqueIndexForUserBadge(x base.EngineMigration) error {
func AddUniqueIndexForUserBadge(_ context.Context, x base.EngineMigration) error {
// remove possible duplicated records in table user_badge
type result struct {
UserID int64
+1 -1
View File
@@ -56,7 +56,7 @@ func Test_AddUniqueIndexForUserBadge(t *testing.T) {
assert.Equal(t, int64(6), totalCount)
// run the migration
if err := AddUniqueIndexForUserBadge(x); err != nil {
if err := AddUniqueIndexForUserBadge(t.Context(), x); err != nil {
assert.NoError(t, err)
return
}
+3 -1
View File
@@ -4,12 +4,14 @@
package v1_26
import (
"context"
"gitea.dev/modelmigration/base"
"xorm.io/xorm"
)
func AddNameToWebhook(x base.EngineMigration) error {
func AddNameToWebhook(_ context.Context, x base.EngineMigration) error {
type Webhook struct {
Name string `xorm:"VARCHAR(255) NOT NULL DEFAULT ''"`
}