mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-04 06:32:56 +02:00
refactor(modelmigration): thread context through migration functions (#38758)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -480,13 +480,13 @@ func DropTableColumns(sess Session, tableName string, columnNames ...string) (er
|
||||
}
|
||||
|
||||
// ModifyColumn will modify column's type or other property. SQLITE is not supported
|
||||
func ModifyColumn(x EngineMigration, tableName string, col *schemas.Column) error {
|
||||
func ModifyColumn(ctx context.Context, x EngineMigration, tableName string, col *schemas.Column) error {
|
||||
var indexes map[string]*schemas.Index
|
||||
var err error
|
||||
// MSSQL have to remove index at first, otherwise alter column will fail
|
||||
// ref. https://sqlzealots.com/2018/05/09/error-message-the-index-is-dependent-on-column-alter-table-alter-column-failed-because-one-or-more-objects-access-this-column/
|
||||
if x.Dialect().URI().DBType == schemas.MSSQL {
|
||||
indexes, err = x.Dialect().GetIndexes(x.DB(), context.Background(), tableName)
|
||||
indexes, err = x.Dialect().GetIndexes(x.DB(), ctx, tableName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -49,15 +49,8 @@ type migration struct {
|
||||
}
|
||||
|
||||
// newMigration creates a new migration
|
||||
func newMigration[T func(base.EngineMigration) error | func(context.Context, base.EngineMigration) error](idNumber int64, desc string, fn T) *migration {
|
||||
m := &migration{idNumber: idNumber, description: desc}
|
||||
var ok bool
|
||||
if m.migrate, ok = any(fn).(func(context.Context, base.EngineMigration) error); !ok {
|
||||
m.migrate = func(ctx context.Context, x base.EngineMigration) error {
|
||||
return any(fn).(func(base.EngineMigration) error)(x)
|
||||
}
|
||||
}
|
||||
return m
|
||||
func newMigration(idNumber int64, desc string, fn func(context.Context, base.EngineMigration) error) *migration {
|
||||
return &migration{idNumber: idNumber, description: desc, migrate: fn}
|
||||
}
|
||||
|
||||
// Migrate executes the migration
|
||||
@@ -72,7 +65,7 @@ type Version struct {
|
||||
}
|
||||
|
||||
// Use noopMigration when there is a migration that has been no-oped
|
||||
var noopMigration = func(_ base.EngineMigration) error { return nil }
|
||||
var noopMigration = func(_ context.Context, _ base.EngineMigration) error { return nil }
|
||||
|
||||
var preparedMigrations []*migration
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_10
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -11,7 +12,7 @@ import (
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func UpdateMigrationServiceTypes(x base.EngineMigration) error {
|
||||
func UpdateMigrationServiceTypes(_ context.Context, x base.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64
|
||||
OriginalServiceType int `xorm:"index default(0)"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func ChangeSomeColumnsLengthOfExternalLoginUser(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func ChangeSomeColumnsLengthOfExternalLoginUser(_ context.Context, x base.EngineMigration) error {
|
||||
type ExternalLoginUser struct {
|
||||
AccessToken string `xorm:"TEXT"`
|
||||
AccessTokenSecret string `xorm:"TEXT"`
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_10
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
|
||||
@@ -14,7 +15,7 @@ func hashContext(context string) string {
|
||||
return fmt.Sprintf("%x", sha1.Sum([]byte(context)))
|
||||
}
|
||||
|
||||
func AddCommitStatusContext(x base.EngineMigration) error {
|
||||
func AddCommitStatusContext(_ context.Context, x base.EngineMigration) error {
|
||||
type CommitStatus struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
ContextHash string `xorm:"char(40) index"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddOriginalMigrationInfo(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddOriginalMigrationInfo(_ context.Context, x base.EngineMigration) error {
|
||||
// Issue see models/issue.go
|
||||
type Issue struct {
|
||||
OriginalAuthor string
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func ChangeSomeColumnsLengthOfRepo(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func ChangeSomeColumnsLengthOfRepo(_ context.Context, x base.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Description string `xorm:"TEXT"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddIndexOnRepositoryAndComment(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddIndexOnRepositoryAndComment(_ context.Context, x base.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
OwnerID int64 `xorm:"index"`
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
package v1_10
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func RemoveLingeringIndexStatus(x base.EngineMigration) error {
|
||||
func RemoveLingeringIndexStatus(_ context.Context, x base.EngineMigration) error {
|
||||
_, err := x.Exec(builder.Delete(builder.NotIn("`repo_id`", builder.Select("`id`").From("`repository`"))).From("`repo_indexer_status`"))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddEmailNotificationEnabledToUser(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddEmailNotificationEnabledToUser(_ context.Context, x base.EngineMigration) error {
|
||||
// User see models/user.go
|
||||
type User struct {
|
||||
EmailNotificationsPreference string `xorm:"VARCHAR(20) NOT NULL DEFAULT 'enabled'"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddStatusCheckColumnsForProtectedBranches(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddStatusCheckColumnsForProtectedBranches(_ context.Context, x base.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
EnableStatusCheck bool `xorm:"NOT NULL DEFAULT false"`
|
||||
StatusCheckContexts []string `xorm:"JSON TEXT"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddCrossReferenceColumns(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddCrossReferenceColumns(_ context.Context, x base.EngineMigration) error {
|
||||
// Comment see models/comment.go
|
||||
type Comment struct {
|
||||
RefRepoID int64 `xorm:"index"`
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_10
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -11,7 +12,7 @@ import (
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
func DeleteOrphanedAttachments(x base.EngineMigration) error {
|
||||
func DeleteOrphanedAttachments(_ context.Context, x base.EngineMigration) error {
|
||||
type Attachment struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
UUID string `xorm:"uuid UNIQUE"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddRepoAdminChangeTeamAccessColumnForUser(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddRepoAdminChangeTeamAccessColumnForUser(_ context.Context, x base.EngineMigration) error {
|
||||
type User struct {
|
||||
RepoAdminChangeTeamAccess bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddOriginalAuthorOnMigratedReleases(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddOriginalAuthorOnMigratedReleases(_ context.Context, x base.EngineMigration) error {
|
||||
type Release struct {
|
||||
ID int64
|
||||
OriginalAuthor string
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_10
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
func AddTaskTable(x base.EngineMigration) error {
|
||||
func AddTaskTable(_ context.Context, x base.EngineMigration) error {
|
||||
// TaskType defines task type
|
||||
type TaskType int
|
||||
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func DropColumnHeadUserNameOnPullRequest(x base.EngineMigration) error {
|
||||
func DropColumnHeadUserNameOnPullRequest(_ context.Context, x base.EngineMigration) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Begin(); err != nil {
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddWhitelistDeployKeysToBranches(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddWhitelistDeployKeysToBranches(_ context.Context, x base.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
ID int64
|
||||
WhitelistDeployKeys bool `xorm:"NOT NULL DEFAULT false"`
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func RemoveLabelUneededCols(x base.EngineMigration) error {
|
||||
func RemoveLabelUneededCols(_ context.Context, x base.EngineMigration) error {
|
||||
// Make sure the columns exist before dropping them
|
||||
type Label struct {
|
||||
QueryString string
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddTeamIncludesAllRepositories(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddTeamIncludesAllRepositories(_ context.Context, x base.EngineMigration) error {
|
||||
type Team struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
IncludesAllRepositories bool `xorm:"NOT NULL DEFAULT false"`
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
// RepoWatchMode specifies what kind of watch the user has on a repository
|
||||
type RepoWatchMode int8
|
||||
@@ -14,7 +18,7 @@ type Watch struct {
|
||||
Mode RepoWatchMode `xorm:"SMALLINT NOT NULL DEFAULT 1"`
|
||||
}
|
||||
|
||||
func AddModeColumnToWatch(x base.EngineMigration) error {
|
||||
func AddModeColumnToWatch(_ context.Context, x base.EngineMigration) error {
|
||||
if err := x.Sync(new(Watch)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddTemplateToRepo(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddTemplateToRepo(_ context.Context, x base.EngineMigration) error {
|
||||
type Repository struct {
|
||||
IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"`
|
||||
TemplateID int64 `xorm:"INDEX"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddCommentIDOnNotification(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddCommentIDOnNotification(_ context.Context, x base.EngineMigration) error {
|
||||
type Notification struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
CommentID int64
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddCanCreateOrgRepoColumnForTeam(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddCanCreateOrgRepoColumnForTeam(_ context.Context, x base.EngineMigration) error {
|
||||
type Team struct {
|
||||
CanCreateOrgRepo bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func ChangeReviewContentToText(x base.EngineMigration) error {
|
||||
func ChangeReviewContentToText(_ context.Context, x base.EngineMigration) error {
|
||||
switch x.Dialect().URI().DBType {
|
||||
case schemas.MYSQL:
|
||||
_, err := x.Exec("ALTER TABLE review MODIFY COLUMN content TEXT")
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddBranchProtectionCanPushAndEnableWhitelist(x base.EngineMigration) error {
|
||||
func AddBranchProtectionCanPushAndEnableWhitelist(_ context.Context, x base.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
CanPush bool `xorm:"NOT NULL DEFAULT false"`
|
||||
EnableApprovalsWhitelist bool `xorm:"NOT NULL DEFAULT false"`
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -14,7 +15,7 @@ import (
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func RemoveAttachmentMissedRepo(x base.EngineMigration) error {
|
||||
func RemoveAttachmentMissedRepo(_ context.Context, x base.EngineMigration) error {
|
||||
type Attachment struct {
|
||||
UUID string `xorm:"uuid"`
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func FeatureChangeTargetBranch(x base.EngineMigration) error {
|
||||
func FeatureChangeTargetBranch(_ context.Context, x base.EngineMigration) error {
|
||||
type Comment struct {
|
||||
OldRef string
|
||||
NewRef string
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func SanitizeOriginalURL(x base.EngineMigration) error {
|
||||
func SanitizeOriginalURL(_ context.Context, x base.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64
|
||||
OriginalURL string `xorm:"VARCHAR(2048)"`
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -18,7 +19,7 @@ import (
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
func RenameExistingUserAvatarName(x base.EngineMigration) error {
|
||||
func RenameExistingUserAvatarName(_ context.Context, x base.EngineMigration) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func ExtendTrackedTimes(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func ExtendTrackedTimes(_ context.Context, x base.EngineMigration) error {
|
||||
type TrackedTime struct {
|
||||
Time int64 `xorm:"NOT NULL"`
|
||||
Deleted bool `xorm:"NOT NULL DEFAULT false"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddBlockOnRejectedReviews(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddBlockOnRejectedReviews(_ context.Context, x base.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
BlockOnRejectedReviews bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddReviewCommitAndStale(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddReviewCommitAndStale(_ context.Context, x base.EngineMigration) error {
|
||||
type Review struct {
|
||||
CommitID string `xorm:"VARCHAR(40)"`
|
||||
Stale bool `xorm:"NOT NULL DEFAULT false"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func FixMigratedRepositoryServiceType(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func FixMigratedRepositoryServiceType(_ context.Context, x base.EngineMigration) error {
|
||||
// structs.GithubService:
|
||||
// GithubService = 2
|
||||
_, err := x.Exec("UPDATE repository SET original_service_type = ? WHERE original_url LIKE 'https://github.com/%'", 2)
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddOwnerNameOnRepository(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddOwnerNameOnRepository(_ context.Context, x base.EngineMigration) error {
|
||||
type Repository struct {
|
||||
OwnerName string
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddIsRestricted(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddIsRestricted(_ context.Context, x base.EngineMigration) error {
|
||||
// User see models/user.go
|
||||
type User struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddRequireSignedCommits(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddRequireSignedCommits(_ context.Context, x base.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
RequireSignedCommits bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddReactionOriginals(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddReactionOriginals(_ context.Context, x base.EngineMigration) error {
|
||||
type Reaction struct {
|
||||
OriginalAuthorID int64 `xorm:"INDEX NOT NULL DEFAULT(0)"`
|
||||
OriginalAuthor string
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddUserRepoMissingColumns(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddUserRepoMissingColumns(_ context.Context, x base.EngineMigration) error {
|
||||
type VisibleType int
|
||||
type User struct {
|
||||
PasswdHashAlgo string `xorm:"NOT NULL DEFAULT 'pbkdf2'"`
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddReviewMigrateInfo(x base.EngineMigration) error {
|
||||
func AddReviewMigrateInfo(_ context.Context, x base.EngineMigration) error {
|
||||
type Review struct {
|
||||
OriginalAuthor string
|
||||
OriginalAuthorID int64
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func FixTopicRepositoryCount(x base.EngineMigration) error {
|
||||
func FixTopicRepositoryCount(_ context.Context, x base.EngineMigration) error {
|
||||
_, err := x.Exec(builder.Delete(builder.NotIn("`repo_id`", builder.Select("`id`").From("`repository`"))).From("`repo_topic`"))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
func AddLanguageStats(x base.EngineMigration) error {
|
||||
func AddLanguageStats(_ context.Context, x base.EngineMigration) error {
|
||||
// LanguageStat see models/repo_language_stats.go
|
||||
type LanguageStat struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func PurgeUnusedDependencies(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func PurgeUnusedDependencies(_ context.Context, x base.EngineMigration) error {
|
||||
if _, err := x.Exec("DELETE FROM issue_dependency WHERE issue_id NOT IN (SELECT id FROM issue)"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/json"
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
func ExpandWebhooks(x base.EngineMigration) error {
|
||||
func ExpandWebhooks(_ context.Context, x base.EngineMigration) error {
|
||||
type HookEvents struct {
|
||||
Create bool `json:"create"`
|
||||
Delete bool `json:"delete"`
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddSystemWebhookColumn(x base.EngineMigration) error {
|
||||
func AddSystemWebhookColumn(_ context.Context, x base.EngineMigration) error {
|
||||
type Webhook struct {
|
||||
IsSystemWebhook bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddBranchProtectionProtectedFilesColumn(x base.EngineMigration) error {
|
||||
func AddBranchProtectionProtectedFilesColumn(_ context.Context, x base.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
ProtectedFilePatterns string `xorm:"TEXT"`
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddEmailHashTable(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddEmailHashTable(_ context.Context, x base.EngineMigration) error {
|
||||
// EmailHash represents a pre-generated hash map
|
||||
type EmailHash struct {
|
||||
Hash string `xorm:"pk varchar(32)"`
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddOrgIDLabelColumn(x base.EngineMigration) error {
|
||||
func AddOrgIDLabelColumn(_ context.Context, x base.EngineMigration) error {
|
||||
type Label struct {
|
||||
OrgID int64 `xorm:"INDEX"`
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
@@ -15,7 +16,7 @@ import (
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
func AddCommitDivergenceToPulls(x base.EngineMigration) error {
|
||||
func AddCommitDivergenceToPulls(_ context.Context, x base.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
OwnerID int64 `xorm:"UNIQUE(s) index"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddBlockOnOutdatedBranch(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddBlockOnOutdatedBranch(_ context.Context, x base.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
BlockOnOutdatedBranch bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddResolveDoerIDCommentColumn(x base.EngineMigration) error {
|
||||
func AddResolveDoerIDCommentColumn(_ context.Context, x base.EngineMigration) error {
|
||||
type Comment struct {
|
||||
ResolveDoerID int64
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
func PrependRefsHeadsToIssueRefs(x base.EngineMigration) error {
|
||||
func PrependRefsHeadsToIssueRefs(_ context.Context, x base.EngineMigration) error {
|
||||
var query string
|
||||
|
||||
switch {
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
func FixLanguageStatsToSaveSize(x base.EngineMigration) error {
|
||||
func FixLanguageStatsToSaveSize(_ context.Context, x base.EngineMigration) error {
|
||||
// LanguageStat see models/repo_language_stats.go
|
||||
type LanguageStat struct {
|
||||
Size int64 `xorm:"NOT NULL DEFAULT 0"`
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddKeepActivityPrivateUserColumn(x base.EngineMigration) error {
|
||||
func AddKeepActivityPrivateUserColumn(_ context.Context, x base.EngineMigration) error {
|
||||
type User struct {
|
||||
KeepActivityPrivate bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -4,13 +4,15 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/log"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func SetIsArchivedToFalse(x base.EngineMigration) error {
|
||||
func SetIsArchivedToFalse(_ context.Context, x base.EngineMigration) error {
|
||||
type Repository struct {
|
||||
IsArchived bool `xorm:"INDEX"`
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/log"
|
||||
)
|
||||
|
||||
func RecalculateStars(x base.EngineMigration) (err error) {
|
||||
func RecalculateStars(_ context.Context, x base.EngineMigration) (err error) {
|
||||
// because of issue https://github.com/go-gitea/gitea/issues/11949,
|
||||
// recalculate Stars number for all users to fully fix it.
|
||||
|
||||
|
||||
@@ -4,13 +4,15 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/log"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func UpdateMatrixWebhookHTTPMethod(x base.EngineMigration) error {
|
||||
func UpdateMatrixWebhookHTTPMethod(_ context.Context, x base.EngineMigration) error {
|
||||
matrixHookTaskType := 9 // value comes from the models package
|
||||
type Webhook struct {
|
||||
HTTPMethod string
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
func IncreaseLanguageField(x base.EngineMigration) error {
|
||||
func IncreaseLanguageField(_ context.Context, x base.EngineMigration) error {
|
||||
type LanguageStat struct {
|
||||
RepoID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
|
||||
Language string `xorm:"VARCHAR(50) UNIQUE(s) INDEX NOT NULL"`
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
func AddProjectsInfo(x base.EngineMigration) error {
|
||||
func AddProjectsInfo(_ context.Context, x base.EngineMigration) error {
|
||||
// Create new tables
|
||||
type (
|
||||
ProjectType uint8
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
func CreateReviewsForCodeComments(x base.EngineMigration) error {
|
||||
func CreateReviewsForCodeComments(_ context.Context, x base.EngineMigration) error {
|
||||
// Review
|
||||
type Review struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_13
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func PurgeInvalidDependenciesComments(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func PurgeInvalidDependenciesComments(_ context.Context, x base.EngineMigration) error {
|
||||
_, err := x.Exec("DELETE FROM comment WHERE dependent_issue_id != 0 AND dependent_issue_id NOT IN (SELECT id FROM issue)")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
func AddCreatedAndUpdatedToMilestones(x base.EngineMigration) error {
|
||||
func AddCreatedAndUpdatedToMilestones(_ context.Context, x base.EngineMigration) error {
|
||||
type Milestone struct {
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
func AddPrimaryKeyToRepoTopic(x base.EngineMigration) error {
|
||||
func AddPrimaryKeyToRepoTopic(_ context.Context, x base.EngineMigration) error {
|
||||
// Topic represents a topic of repositories
|
||||
type Topic struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func SetDefaultPasswordToArgon2(x base.EngineMigration) error {
|
||||
func SetDefaultPasswordToArgon2(ctx context.Context, x base.EngineMigration) error {
|
||||
switch {
|
||||
case setting.Database.Type.IsMySQL():
|
||||
_, err := x.Exec("ALTER TABLE `user` ALTER passwd_hash_algo SET DEFAULT 'argon2';")
|
||||
@@ -91,7 +91,7 @@ func SetDefaultPasswordToArgon2(x base.EngineMigration) error {
|
||||
tempTableName := "tmp_recreate__user"
|
||||
column.Default = "'argon2'"
|
||||
|
||||
createTableSQL, _, err := x.Dialect().CreateTableSQL(context.Background(), x.DB(), table, tempTableName)
|
||||
createTableSQL, _, err := x.Dialect().CreateTableSQL(ctx, x.DB(), table, tempTableName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_13
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddTrustModelToRepository(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddTrustModelToRepository(_ context.Context, x base.EngineMigration) error {
|
||||
type Repository struct {
|
||||
TrustModel int
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_13
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddTeamReviewRequestSupport(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddTeamReviewRequestSupport(_ context.Context, x base.EngineMigration) error {
|
||||
type Review struct {
|
||||
ReviewerTeamID int64 `xorm:"NOT NULL DEFAULT 0"`
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
func AddTimeStamps(x base.EngineMigration) error {
|
||||
func AddTimeStamps(_ context.Context, x base.EngineMigration) error {
|
||||
// this will add timestamps where it is useful to have
|
||||
|
||||
// Star represents a starred repo by an user.
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddChangedProtectedFilesPullRequestColumn(x base.EngineMigration) error {
|
||||
func AddChangedProtectedFilesPullRequestColumn(_ context.Context, x base.EngineMigration) error {
|
||||
type PullRequest struct {
|
||||
ChangedProtectedFiles []string `xorm:"TEXT JSON"`
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_14
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func FixRepoTopics(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func FixRepoTopics(_ context.Context, x base.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Topics []string `xorm:"TEXT JSON"`
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
@@ -12,7 +13,7 @@ import (
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
func UpdateCodeCommentReplies(x base.EngineMigration) error {
|
||||
func UpdateCodeCommentReplies(_ context.Context, x base.EngineMigration) error {
|
||||
type Comment struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
CommitSHA string `xorm:"VARCHAR(40)"`
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
func UpdateReactionConstraint(x base.EngineMigration) error {
|
||||
func UpdateReactionConstraint(_ context.Context, x base.EngineMigration) error {
|
||||
// Reaction represents a reactions on issues and comments.
|
||||
type Reaction struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_14
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func AddBlockOnOfficialReviewRequests(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddBlockOnOfficialReviewRequests(_ context.Context, x base.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
BlockOnOfficialReviewRequests bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func ConvertTaskTypeToString(x base.EngineMigration) error {
|
||||
func ConvertTaskTypeToString(ctx context.Context, x base.EngineMigration) error {
|
||||
const (
|
||||
GOGS int = iota + 1
|
||||
SLACK
|
||||
@@ -44,7 +44,7 @@ func ConvertTaskTypeToString(x base.EngineMigration) error {
|
||||
}
|
||||
|
||||
// to keep the migration could be rerun
|
||||
exist, err := x.Dialect().IsColumnExist(x.DB(), context.Background(), "hook_task", "type")
|
||||
exist, err := x.Dialect().IsColumnExist(x.DB(), ctx, "hook_task", "type")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func ConvertWebhookTaskTypeToString(x base.EngineMigration) error {
|
||||
func ConvertWebhookTaskTypeToString(_ context.Context, x base.EngineMigration) error {
|
||||
const (
|
||||
GOGS int = iota + 1
|
||||
SLACK
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func ConvertTopicNameFrom25To50(x base.EngineMigration) error {
|
||||
func ConvertTopicNameFrom25To50(_ context.Context, x base.EngineMigration) error {
|
||||
type Topic struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Name string `xorm:"UNIQUE VARCHAR(50)"`
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
@@ -29,7 +30,7 @@ func (grant *OAuth2Grant) TableName() string {
|
||||
return "oauth2_grant"
|
||||
}
|
||||
|
||||
func AddScopeAndNonceColumnsToOAuth2Grant(x base.EngineMigration) error {
|
||||
func AddScopeAndNonceColumnsToOAuth2Grant(_ context.Context, x base.EngineMigration) error {
|
||||
if err := x.Sync(new(OAuth2Grant)); err != nil {
|
||||
return fmt.Errorf("Sync: %w", err)
|
||||
}
|
||||
|
||||
@@ -4,19 +4,21 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func ConvertHookTaskTypeToVarcharAndTrim(x base.EngineMigration) error {
|
||||
func ConvertHookTaskTypeToVarcharAndTrim(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
|
||||
}
|
||||
|
||||
// HookTask: Typ string `xorm:"VARCHAR(16) index"`
|
||||
if err := base.ModifyColumn(x, "hook_task", &schemas.Column{
|
||||
if err := base.ModifyColumn(ctx, x, "hook_task", &schemas.Column{
|
||||
Name: "typ",
|
||||
SQLType: schemas.SQLType{
|
||||
Name: "VARCHAR",
|
||||
@@ -39,7 +41,7 @@ func ConvertHookTaskTypeToVarcharAndTrim(x base.EngineMigration) error {
|
||||
}
|
||||
|
||||
// Webhook: Type string `xorm:"VARCHAR(16) index"`
|
||||
if err := base.ModifyColumn(x, "webhook", &schemas.Column{
|
||||
if err := base.ModifyColumn(ctx, x, "webhook", &schemas.Column{
|
||||
Name: "type",
|
||||
SQLType: schemas.SQLType{
|
||||
Name: "VARCHAR",
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
|
||||
@@ -16,7 +17,7 @@ import (
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func RecalculateUserEmptyPWD(x base.EngineMigration) (err error) {
|
||||
func RecalculateUserEmptyPWD(_ context.Context, x base.EngineMigration) (err error) {
|
||||
const (
|
||||
algoBcrypt = "bcrypt"
|
||||
algoScrypt = "scrypt"
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddUserRedirect(x base.EngineMigration) (err error) {
|
||||
func AddUserRedirect(_ context.Context, x base.EngineMigration) (err error) {
|
||||
type UserRedirect struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`
|
||||
|
||||
@@ -3,8 +3,12 @@
|
||||
|
||||
package v1_14
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func RecreateUserTableToFixDefaultValues(_ base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func RecreateUserTableToFixDefaultValues(_ context.Context, _ base.EngineMigration) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@
|
||||
|
||||
package v1_14
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func CommentTypeDeleteBranchUseOldRef(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func CommentTypeDeleteBranchUseOldRef(_ context.Context, x base.EngineMigration) error {
|
||||
_, err := x.Exec("UPDATE comment SET old_ref = commit_sha, commit_sha = '' WHERE type = 11")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddDismissedReviewColumn(x base.EngineMigration) error {
|
||||
func AddDismissedReviewColumn(_ context.Context, x base.EngineMigration) error {
|
||||
type Review struct {
|
||||
Dismissed bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddSortingColToProjectBoard(x base.EngineMigration) error {
|
||||
func AddSortingColToProjectBoard(_ context.Context, x base.EngineMigration) error {
|
||||
type ProjectBoard struct {
|
||||
Sorting int8 `xorm:"NOT NULL DEFAULT 0"`
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
func AddSessionTable(x base.EngineMigration) error {
|
||||
func AddSessionTable(_ context.Context, x base.EngineMigration) error {
|
||||
type Session struct {
|
||||
Key string `xorm:"pk CHAR(16)"`
|
||||
Data []byte `xorm:"BLOB"`
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddTimeIDCommentColumn(x base.EngineMigration) error {
|
||||
func AddTimeIDCommentColumn(_ context.Context, x base.EngineMigration) error {
|
||||
type Comment struct {
|
||||
TimeID int64
|
||||
}
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func AddRepoTransfer(x base.EngineMigration) error {
|
||||
func AddRepoTransfer(_ context.Context, x base.EngineMigration) error {
|
||||
type RepoTransfer struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
DoerID int64
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
@@ -12,7 +13,7 @@ import (
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
func FixPostgresIDSequences(x base.EngineMigration) error {
|
||||
func FixPostgresIDSequences(_ context.Context, x base.EngineMigration) error {
|
||||
if !setting.Database.Type.IsPostgreSQL() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,12 +3,16 @@
|
||||
|
||||
package v1_14
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
// RemoveInvalidLabels looks through the database to look for comments and issue_labels
|
||||
// that refer to labels do not belong to the repository or organization that repository
|
||||
// that the issue is in
|
||||
func RemoveInvalidLabels(x base.EngineMigration) error {
|
||||
func RemoveInvalidLabels(_ context.Context, x base.EngineMigration) error {
|
||||
type Comment struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Type int `xorm:"INDEX"`
|
||||
|
||||
@@ -79,7 +79,7 @@ func Test_RemoveInvalidLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
// Run the migration
|
||||
if err := RemoveInvalidLabels(x); err != nil {
|
||||
if err := RemoveInvalidLabels(t.Context(), x); err != nil {
|
||||
t.Errorf("unable to RemoveInvalidLabels: %v", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
// DeleteOrphanedIssueLabels looks through the database for issue_labels where the label no longer exists and deletes them.
|
||||
func DeleteOrphanedIssueLabels(x base.EngineMigration) error {
|
||||
func DeleteOrphanedIssueLabels(_ context.Context, x base.EngineMigration) error {
|
||||
type IssueLabel struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
IssueID int64 `xorm:"UNIQUE(s)"`
|
||||
|
||||
@@ -55,7 +55,7 @@ func Test_DeleteOrphanedIssueLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
// Run the migration
|
||||
if err := DeleteOrphanedIssueLabels(x); err != nil {
|
||||
if err := DeleteOrphanedIssueLabels(t.Context(), x); err != nil {
|
||||
assert.NoError(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user