mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-23 05:03:39 +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_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,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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user