mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-22 20:53:40 +09:00
refactor(modelmigration): thread context through migration functions (#38758)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_22
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func RenameUserThemes(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func RenameUserThemes(_ context.Context, x base.EngineMigration) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_22
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
func CreateAuthTokenTable(x base.EngineMigration) error {
|
||||
func CreateAuthTokenTable(_ context.Context, x base.EngineMigration) error {
|
||||
type AuthToken struct {
|
||||
ID string `xorm:"pk"`
|
||||
TokenHash string
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_22
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddIndexToPullAutoMergeDoerID(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddIndexToPullAutoMergeDoerID(_ context.Context, x base.EngineMigration) error {
|
||||
type PullAutoMerge struct {
|
||||
DoerID int64 `xorm:"INDEX NOT NULL"`
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_22
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
@@ -11,7 +12,7 @@ import (
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func AddCombinedIndexToIssueUser(x base.EngineMigration) error {
|
||||
func AddCombinedIndexToIssueUser(_ context.Context, x base.EngineMigration) error {
|
||||
type OldIssueUser struct {
|
||||
IssueID int64
|
||||
UID int64
|
||||
|
||||
@@ -24,5 +24,5 @@ func Test_AddCombinedIndexToIssueUser(t *testing.T) {
|
||||
x, deferable := migrationtest.PrepareTestEnv(t, 0, new(IssueUser))
|
||||
defer deferable()
|
||||
|
||||
assert.NoError(t, AddCombinedIndexToIssueUser(x))
|
||||
assert.NoError(t, AddCombinedIndexToIssueUser(t.Context(), x))
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
package v1_22
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddIgnoreStaleApprovalsColumnToProtectedBranchTable(x base.EngineMigration) error {
|
||||
func AddIgnoreStaleApprovalsColumnToProtectedBranchTable(_ context.Context, x base.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
IgnoreStaleApprovals bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_22
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
@@ -11,7 +12,7 @@ import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddPreviousDurationToActionRun(x base.EngineMigration) error {
|
||||
func AddPreviousDurationToActionRun(_ context.Context, x base.EngineMigration) error {
|
||||
type ActionRun struct {
|
||||
PreviousDuration time.Duration
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package v1_22
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
@@ -100,7 +101,7 @@ func addObjectFormatNameToRepository(x base.EngineMigration) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func AdjustDBForSha256(x base.EngineMigration) error {
|
||||
func AdjustDBForSha256(_ context.Context, x base.EngineMigration) error {
|
||||
if err := expandHashReferencesToSha256(x); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ func Test_RepositoryFormat(t *testing.T) {
|
||||
x, deferable := PrepareOldRepository(t)
|
||||
defer deferable()
|
||||
|
||||
assert.NoError(t, AdjustDBForSha256(x))
|
||||
assert.NoError(t, AdjustDBForSha256(t.Context(), x))
|
||||
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
|
||||
package v1_22
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
type BadgeUnique struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
@@ -14,7 +18,7 @@ func (BadgeUnique) TableName() string {
|
||||
return "badge"
|
||||
}
|
||||
|
||||
func UseSlugInsteadOfIDForBadges(x base.EngineMigration) error {
|
||||
func UseSlugInsteadOfIDForBadges(_ context.Context, x base.EngineMigration) error {
|
||||
type Badge struct {
|
||||
Slug string
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func Test_UpdateBadgeColName(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
if err := UseSlugInsteadOfIDForBadges(x); err != nil {
|
||||
if err := UseSlugInsteadOfIDForBadges(t.Context(), x); err != nil {
|
||||
assert.NoError(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package v1_22
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
@@ -20,6 +22,6 @@ func (*Blocking) TableName() string {
|
||||
return "user_blocking"
|
||||
}
|
||||
|
||||
func AddUserBlockingTable(x base.EngineMigration) error {
|
||||
func AddUserBlockingTable(_ context.Context, x base.EngineMigration) error {
|
||||
return x.Sync(&Blocking{})
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
package v1_22
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddDefaultWikiBranch(x base.EngineMigration) error {
|
||||
func AddDefaultWikiBranch(_ context.Context, x base.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64
|
||||
DefaultWikiBranch string
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package v1_22
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
@@ -13,7 +15,7 @@ type HookTask struct {
|
||||
PayloadVersion int `xorm:"DEFAULT 1"`
|
||||
}
|
||||
|
||||
func AddPayloadVersionToHookTaskTable(x base.EngineMigration) error {
|
||||
func AddPayloadVersionToHookTaskTable(_ context.Context, x base.EngineMigration) error {
|
||||
// create missing column
|
||||
if _, err := x.SyncWithOptions(xorm.SyncOptions{
|
||||
IgnoreIndices: true,
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
package v1_22
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddCommentIDIndexofAttachment(x base.EngineMigration) error {
|
||||
func AddCommentIDIndexofAttachment(_ context.Context, x base.EngineMigration) error {
|
||||
type Attachment struct {
|
||||
CommentID int64 `xorm:"INDEX"`
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package v1_22
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/setting"
|
||||
"gitea.dev/modules/timeutil"
|
||||
@@ -28,7 +30,7 @@ func (ProjectBoardV293) TableName() string {
|
||||
}
|
||||
|
||||
// CheckProjectColumnsConsistency ensures there is exactly one default board per project present
|
||||
func CheckProjectColumnsConsistency(x base.EngineMigration) error {
|
||||
func CheckProjectColumnsConsistency(_ context.Context, x base.EngineMigration) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ func Test_CheckProjectColumnsConsistency(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
assert.NoError(t, CheckProjectColumnsConsistency(x))
|
||||
assert.NoError(t, CheckProjectColumnsConsistency(t.Context(), x))
|
||||
|
||||
// check if default column was added
|
||||
var defaultColumn ProjectBoardV293
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_22
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
@@ -12,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
// AddUniqueIndexForProjectIssue adds unique indexes for project issue table
|
||||
func AddUniqueIndexForProjectIssue(x base.EngineMigration) error {
|
||||
func AddUniqueIndexForProjectIssue(_ context.Context, x base.EngineMigration) error {
|
||||
// remove possible duplicated records in table project_issue
|
||||
type result struct {
|
||||
IssueID int64
|
||||
|
||||
@@ -30,7 +30,7 @@ func Test_AddUniqueIndexForProjectIssue(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 2, cnt)
|
||||
|
||||
assert.NoError(t, AddUniqueIndexForProjectIssue(x))
|
||||
assert.NoError(t, AddUniqueIndexForProjectIssue(t.Context(), x))
|
||||
|
||||
cnt, err = x.Table("project_issue").Where("project_id=1 AND issue_id=1").Count()
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_22
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddCommitStatusSummary(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddCommitStatusSummary(_ context.Context, x base.EngineMigration) error {
|
||||
type CommitStatusSummary struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RepoID int64 `xorm:"INDEX UNIQUE(repo_id_sha)"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_22
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddCommitStatusSummary2(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddCommitStatusSummary2(_ context.Context, x base.EngineMigration) error {
|
||||
type CommitStatusSummary struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
TargetURL string `xorm:"TEXT"`
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
package v1_22
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddRepoUnitEveryoneAccessMode(x base.EngineMigration) error {
|
||||
func AddRepoUnitEveryoneAccessMode(_ context.Context, x base.EngineMigration) error {
|
||||
type RepoUnit struct { //revive:disable-line:exported
|
||||
EveryoneAccessMode int `xorm:"NOT NULL DEFAULT 0"`
|
||||
}
|
||||
|
||||
@@ -3,8 +3,12 @@
|
||||
|
||||
package v1_22
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func DropWronglyCreatedTable(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func DropWronglyCreatedTable(_ context.Context, x base.EngineMigration) error {
|
||||
return x.DropTables("o_auth2_application")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user