mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-23 13:13:38 +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_18
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
func CreateUserBadgesTable(x base.EngineMigration) error {
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
func CreateUserBadgesTable(_ context.Context, x base.EngineMigration) error {
|
||||
type Badge struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Description string
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_18
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
func AlterPublicGPGKeyContentFieldsToMediumText(x base.EngineMigration) error {
|
||||
func AlterPublicGPGKeyContentFieldsToMediumText(_ context.Context, x base.EngineMigration) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Begin(); err != nil {
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
package v1_18
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func FixPackageSemverField(x base.EngineMigration) error {
|
||||
func FixPackageSemverField(_ context.Context, x base.EngineMigration) error {
|
||||
_, err := x.Exec(builder.Update(builder.Eq{"semver_compatible": false}).From("`package`").Where(builder.In("`type`", "conan", "generic")))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package v1_18
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
@@ -17,6 +19,6 @@ type SystemSetting struct {
|
||||
Updated timeutil.TimeStamp `xorm:"updated"`
|
||||
}
|
||||
|
||||
func CreateSystemSettingsTable(x base.EngineMigration) error {
|
||||
func CreateSystemSettingsTable(_ context.Context, x base.EngineMigration) error {
|
||||
return x.Sync(new(SystemSetting))
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package v1_18
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/timeutil"
|
||||
)
|
||||
|
||||
func AddTeamInviteTable(x base.EngineMigration) error {
|
||||
func AddTeamInviteTable(_ context.Context, x base.EngineMigration) error {
|
||||
type TeamInvite struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Token string `xorm:"UNIQUE(token) INDEX NOT NULL DEFAULT ''"`
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package v1_18
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
@@ -12,7 +13,7 @@ import (
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func UpdateOpenMilestoneCounts(x base.EngineMigration) error {
|
||||
func UpdateOpenMilestoneCounts(_ context.Context, x base.EngineMigration) error {
|
||||
var openMilestoneIDs []int64
|
||||
err := x.Table("milestone").Select("id").Where(builder.Neq{"is_closed": 1}).Find(&openMilestoneIDs)
|
||||
if err != nil {
|
||||
|
||||
@@ -40,7 +40,7 @@ func Test_UpdateOpenMilestoneCounts(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := UpdateOpenMilestoneCounts(x); err != nil {
|
||||
if err := UpdateOpenMilestoneCounts(t.Context(), x); err != nil {
|
||||
assert.NoError(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3,10 +3,14 @@
|
||||
|
||||
package v1_18
|
||||
|
||||
import "gitea.dev/modelmigration/base"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
)
|
||||
|
||||
// AddConfidentialColumnToOAuth2ApplicationTable: add ConfidentialClient column, setting existing rows to true
|
||||
func AddConfidentialClientColumnToOAuth2ApplicationTable(x base.EngineMigration) error {
|
||||
func AddConfidentialClientColumnToOAuth2ApplicationTable(_ context.Context, x base.EngineMigration) error {
|
||||
type oauth2Application struct {
|
||||
ID int64
|
||||
ConfidentialClient bool `xorm:"NOT NULL DEFAULT TRUE"`
|
||||
|
||||
@@ -24,7 +24,7 @@ func Test_AddConfidentialClientColumnToOAuth2ApplicationTable(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := AddConfidentialClientColumnToOAuth2ApplicationTable(x); err != nil {
|
||||
if err := AddConfidentialClientColumnToOAuth2ApplicationTable(t.Context(), x); err != nil {
|
||||
assert.NoError(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user