mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-16 01:43:24 +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_20
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddNeedApprovalToActionRun(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddNeedApprovalToActionRun(_ context.Context, x base.EngineMigration) error {
|
||||
/*
|
||||
New index: TriggerUserID
|
||||
New fields: NeedApproval, ApprovedBy
|
||||
|
||||
@@ -10,19 +10,19 @@ import (
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
func RenameWebhookOrgToOwner(x base.EngineMigration) error {
|
||||
func RenameWebhookOrgToOwner(ctx context.Context, x base.EngineMigration) error {
|
||||
type Webhook struct {
|
||||
OrgID int64 `xorm:"INDEX"`
|
||||
}
|
||||
|
||||
// This migration maybe rerun so that we should check if it has been run
|
||||
ownerExist, err := x.Dialect().IsColumnExist(x.DB(), context.Background(), "webhook", "owner_id")
|
||||
ownerExist, err := x.Dialect().IsColumnExist(x.DB(), ctx, "webhook", "owner_id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ownerExist {
|
||||
orgExist, err := x.Dialect().IsColumnExist(x.DB(), context.Background(), "webhook", "org_id")
|
||||
orgExist, err := x.Dialect().IsColumnExist(x.DB(), ctx, "webhook", "org_id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_20
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddNewColumnForProject(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddNewColumnForProject(_ context.Context, x base.EngineMigration) error {
|
||||
type Project struct {
|
||||
OwnerID int64 `xorm:"INDEX"`
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
package v1_20
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/log"
|
||||
)
|
||||
|
||||
// FixIncorrectProjectType: set individual project's type from 3(TypeOrganization) to 1(TypeIndividual)
|
||||
func FixIncorrectProjectType(x base.EngineMigration) error {
|
||||
func FixIncorrectProjectType(_ context.Context, x base.EngineMigration) error {
|
||||
type User struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Type int
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_20
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddVersionToActionRunner(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddVersionToActionRunner(_ context.Context, x base.EngineMigration) error {
|
||||
type ActionRunner struct {
|
||||
Version string `xorm:"VARCHAR(64)"` // the version of act_runner
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package v1_20
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
|
||||
@@ -40,6 +42,6 @@ func (a *Action) TableIndices() []*schemas.Index {
|
||||
return indices
|
||||
}
|
||||
|
||||
func ImproveActionTableIndices(x base.EngineMigration) error {
|
||||
func ImproveActionTableIndices(_ context.Context, x base.EngineMigration) error {
|
||||
return x.Sync(new(Action))
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
package v1_20
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/json"
|
||||
)
|
||||
|
||||
func ChangeContainerMetadataMultiArch(x base.EngineMigration) error {
|
||||
func ChangeContainerMetadataMultiArch(_ context.Context, x base.EngineMigration) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_20
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/log"
|
||||
)
|
||||
|
||||
func FixIncorrectOwnerTeamUnitAccessMode(x base.EngineMigration) error {
|
||||
func FixIncorrectOwnerTeamUnitAccessMode(_ context.Context, x base.EngineMigration) error {
|
||||
type UnitType int
|
||||
type AccessMode int
|
||||
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_20
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/log"
|
||||
)
|
||||
|
||||
func FixIncorrectAdminTeamUnitAccessMode(x base.EngineMigration) error {
|
||||
func FixIncorrectAdminTeamUnitAccessMode(_ context.Context, x base.EngineMigration) error {
|
||||
type UnitType int
|
||||
type AccessMode int
|
||||
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_20
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/log"
|
||||
)
|
||||
|
||||
func FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam(x base.EngineMigration) error {
|
||||
func FixExternalTrackerAndExternalWikiAccessModeInOwnerAndAdminTeam(_ context.Context, x base.EngineMigration) error {
|
||||
type UnitType int
|
||||
type AccessMode int
|
||||
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_20
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddActionTaskOutputTable(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddActionTaskOutputTable(_ context.Context, x base.EngineMigration) error {
|
||||
type ActionTaskOutput struct {
|
||||
ID int64
|
||||
TaskID int64 `xorm:"INDEX UNIQUE(task_id_output_key)"`
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_20
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
func AddArchivedUnixToRepository(x base.EngineMigration) error {
|
||||
func AddArchivedUnixToRepository(_ context.Context, x base.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"`
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_20
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddIsInternalColumnToPackage(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddIsInternalColumnToPackage(_ context.Context, x base.EngineMigration) error {
|
||||
type Package struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
OwnerID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_20
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
func CreateActionArtifactTable(x base.EngineMigration) error {
|
||||
func CreateActionArtifactTable(_ context.Context, x base.EngineMigration) error {
|
||||
// ActionArtifact is a file that is stored in the artifact storage.
|
||||
type ActionArtifact struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_20
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddPinOrderToIssue(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddPinOrderToIssue(_ context.Context, x base.EngineMigration) error {
|
||||
type Issue struct {
|
||||
PinOrder int `xorm:"DEFAULT 0"`
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_20
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -318,7 +319,7 @@ type AccessToken struct {
|
||||
Scope string
|
||||
}
|
||||
|
||||
func ConvertScopedAccessTokens(x base.EngineMigration) error {
|
||||
func ConvertScopedAccessTokens(_ context.Context, x base.EngineMigration) error {
|
||||
var tokens []*AccessToken
|
||||
|
||||
if err := x.Find(&tokens); err != nil {
|
||||
|
||||
@@ -86,11 +86,11 @@ func Test_ConvertScopedAccessTokens(t *testing.T) {
|
||||
}
|
||||
|
||||
// migrate the scopes
|
||||
err = ConvertScopedAccessTokens(x)
|
||||
err = ConvertScopedAccessTokens(t.Context(), x)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// migrate the scopes again (migration should be idempotent)
|
||||
err = ConvertScopedAccessTokens(x)
|
||||
err = ConvertScopedAccessTokens(t.Context(), x)
|
||||
assert.NoError(t, err)
|
||||
|
||||
tokens := make([]AccessToken, 0)
|
||||
|
||||
Reference in New Issue
Block a user