mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-24 05:33:40 +09:00
refactor(modelmigration): thread context through migration functions (#38758)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user