mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 22:13:26 +09:00
chore(db): introduce db.Session and db.EngineMigration interfaces (#37746)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: wxiaoguang <2114189+wxiaoguang@users.noreply.github.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
co-authored by
copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
wxiaoguang
wxiaoguang
parent
d9149d8a0a
commit
94e3482d1a
@@ -11,17 +11,17 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
// RecreateTables will recreate the tables for the provided beans using the newly provided bean definition and move all data to that new table
|
||||
// WARNING: YOU MUST PROVIDE THE FULL BEAN DEFINITION
|
||||
func RecreateTables(beans ...any) func(*xorm.Engine) error {
|
||||
return func(x *xorm.Engine) error {
|
||||
func RecreateTables(beans ...any) func(db.EngineMigration) error {
|
||||
return func(x db.EngineMigration) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Begin(); err != nil {
|
||||
@@ -41,7 +41,7 @@ func RecreateTables(beans ...any) func(*xorm.Engine) error {
|
||||
// RecreateTable will recreate the table using the newly provided bean definition and move all data to that new table
|
||||
// WARNING: YOU MUST PROVIDE THE FULL BEAN DEFINITION
|
||||
// WARNING: YOU MUST COMMIT THE SESSION AT THE END
|
||||
func RecreateTable(sess *xorm.Session, bean any) error {
|
||||
func RecreateTable(sess db.Session, bean any) error {
|
||||
// TODO: This will not work if there are foreign keys
|
||||
|
||||
tableName := sess.Engine().TableName(bean)
|
||||
@@ -304,7 +304,7 @@ func RecreateTable(sess *xorm.Session, bean any) error {
|
||||
}
|
||||
|
||||
// WARNING: YOU MUST COMMIT THE SESSION AT THE END
|
||||
func DropTableColumns(sess *xorm.Session, tableName string, columnNames ...string) (err error) {
|
||||
func DropTableColumns(sess db.Session, tableName string, columnNames ...string) (err error) {
|
||||
if tableName == "" || len(columnNames) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -474,7 +474,7 @@ func DropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
|
||||
}
|
||||
|
||||
// ModifyColumn will modify column's type or other property. SQLITE is not supported
|
||||
func ModifyColumn(x *xorm.Engine, tableName string, col *schemas.Column) error {
|
||||
func ModifyColumn(x db.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
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations/v1_10"
|
||||
"code.gitea.io/gitea/models/migrations/v1_11"
|
||||
"code.gitea.io/gitea/models/migrations/v1_12"
|
||||
@@ -35,7 +36,6 @@ import (
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/names"
|
||||
)
|
||||
|
||||
@@ -44,23 +44,23 @@ const minDBVersion = 70 // Gitea 1.5.3
|
||||
type migration struct {
|
||||
idNumber int64 // DB version is "the last migration's idNumber" + 1
|
||||
description string
|
||||
migrate func(context.Context, *xorm.Engine) error
|
||||
migrate func(context.Context, db.EngineMigration) error
|
||||
}
|
||||
|
||||
// newMigration creates a new migration
|
||||
func newMigration[T func(*xorm.Engine) error | func(context.Context, *xorm.Engine) error](idNumber int64, desc string, fn T) *migration {
|
||||
func newMigration[T func(db.EngineMigration) error | func(context.Context, db.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, *xorm.Engine) error); !ok {
|
||||
m.migrate = func(ctx context.Context, x *xorm.Engine) error {
|
||||
return any(fn).(func(*xorm.Engine) error)(x)
|
||||
if m.migrate, ok = any(fn).(func(context.Context, db.EngineMigration) error); !ok {
|
||||
m.migrate = func(ctx context.Context, x db.EngineMigration) error {
|
||||
return any(fn).(func(db.EngineMigration) error)(x)
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// Migrate executes the migration
|
||||
func (m *migration) Migrate(ctx context.Context, x *xorm.Engine) error {
|
||||
func (m *migration) Migrate(ctx context.Context, x db.EngineMigration) error {
|
||||
return m.migrate(ctx, x)
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ type Version struct {
|
||||
}
|
||||
|
||||
// Use noopMigration when there is a migration that has been no-oped
|
||||
var noopMigration = func(_ *xorm.Engine) error { return nil }
|
||||
var noopMigration = func(_ db.EngineMigration) error { return nil }
|
||||
|
||||
var preparedMigrations []*migration
|
||||
|
||||
@@ -417,7 +417,7 @@ func prepareMigrationTasks() []*migration {
|
||||
}
|
||||
|
||||
// GetCurrentDBVersion returns the current db version
|
||||
func GetCurrentDBVersion(x *xorm.Engine) (int64, error) {
|
||||
func GetCurrentDBVersion(x db.EngineMigration) (int64, error) {
|
||||
if err := x.Sync(new(Version)); err != nil {
|
||||
return -1, fmt.Errorf("sync: %w", err)
|
||||
}
|
||||
@@ -450,7 +450,7 @@ func ExpectedDBVersion() int64 {
|
||||
}
|
||||
|
||||
// EnsureUpToDate will check if the db is at the correct version
|
||||
func EnsureUpToDate(ctx context.Context, x *xorm.Engine) error {
|
||||
func EnsureUpToDate(ctx context.Context, x db.EngineMigration) error {
|
||||
currentDB, err := GetCurrentDBVersion(x)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -482,7 +482,7 @@ func migrationIDNumberToDBVersion(idNumber int64) int64 {
|
||||
}
|
||||
|
||||
// Migrate database to current version
|
||||
func Migrate(ctx context.Context, x *xorm.Engine) error {
|
||||
func Migrate(ctx context.Context, x db.EngineMigration) error {
|
||||
migrations := prepareMigrationTasks()
|
||||
maxDBVer := calcDBVersion(migrations)
|
||||
|
||||
@@ -501,7 +501,7 @@ func Migrate(ctx context.Context, x *xorm.Engine) error {
|
||||
// XORM model framework will create all tables when initializing.
|
||||
currentVersion.ID = 0
|
||||
currentVersion.Version = maxDBVer
|
||||
if _, err = x.InsertOne(currentVersion); err != nil {
|
||||
if _, err = x.Insert(currentVersion); err != nil {
|
||||
return fmt.Errorf("insert: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
@@ -24,7 +23,7 @@ import (
|
||||
// Provide models to be sync'd with the database - in particular any models you expect fixtures to be loaded from.
|
||||
//
|
||||
// fixtures in `models/migrations/fixtures/<TestName>` will be loaded automatically
|
||||
func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, func()) {
|
||||
func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (db.EngineMigration, func()) {
|
||||
t.Helper()
|
||||
ourSkip := 2
|
||||
ourSkip += skip
|
||||
@@ -89,7 +88,7 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu
|
||||
return x, deferFn
|
||||
}
|
||||
|
||||
func LoadTableSchemasMap(t *testing.T, x *xorm.Engine) map[string]*schemas.Table {
|
||||
func LoadTableSchemasMap(t *testing.T, x db.EngineMigration) map[string]*schemas.Table {
|
||||
tables, err := x.DBMetas()
|
||||
require.NoError(t, err)
|
||||
tableMap := make(map[string]*schemas.Table)
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func UpdateMigrationServiceTypes(x *xorm.Engine) error {
|
||||
func UpdateMigrationServiceTypes(x db.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64
|
||||
OriginalServiceType int `xorm:"index default(0)"`
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func ChangeSomeColumnsLengthOfExternalLoginUser(x *xorm.Engine) error {
|
||||
func ChangeSomeColumnsLengthOfExternalLoginUser(x db.EngineMigration) error {
|
||||
type ExternalLoginUser struct {
|
||||
AccessToken string `xorm:"TEXT"`
|
||||
AccessTokenSecret string `xorm:"TEXT"`
|
||||
|
||||
@@ -7,14 +7,14 @@ import (
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func hashContext(context string) string {
|
||||
return fmt.Sprintf("%x", sha1.Sum([]byte(context)))
|
||||
}
|
||||
|
||||
func AddCommitStatusContext(x *xorm.Engine) error {
|
||||
func AddCommitStatusContext(x db.EngineMigration) error {
|
||||
type CommitStatus struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
ContextHash string `xorm:"char(40) index"`
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "xorm.io/xorm"
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddOriginalMigrationInfo(x *xorm.Engine) error {
|
||||
func AddOriginalMigrationInfo(x db.EngineMigration) error {
|
||||
// Issue see models/issue.go
|
||||
type Issue struct {
|
||||
OriginalAuthor string
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "xorm.io/xorm"
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func ChangeSomeColumnsLengthOfRepo(x *xorm.Engine) error {
|
||||
func ChangeSomeColumnsLengthOfRepo(x db.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Description string `xorm:"TEXT"`
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "xorm.io/xorm"
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddIndexOnRepositoryAndComment(x *xorm.Engine) error {
|
||||
func AddIndexOnRepositoryAndComment(x db.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
OwnerID int64 `xorm:"index"`
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
package v1_10
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func RemoveLingeringIndexStatus(x *xorm.Engine) error {
|
||||
func RemoveLingeringIndexStatus(x db.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,9 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "xorm.io/xorm"
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddEmailNotificationEnabledToUser(x *xorm.Engine) error {
|
||||
func AddEmailNotificationEnabledToUser(x db.EngineMigration) error {
|
||||
// User see models/user.go
|
||||
type User struct {
|
||||
EmailNotificationsPreference string `xorm:"VARCHAR(20) NOT NULL DEFAULT 'enabled'"`
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "xorm.io/xorm"
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddStatusCheckColumnsForProtectedBranches(x *xorm.Engine) error {
|
||||
func AddStatusCheckColumnsForProtectedBranches(x db.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
EnableStatusCheck bool `xorm:"NOT NULL DEFAULT false"`
|
||||
StatusCheckContexts []string `xorm:"JSON TEXT"`
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "xorm.io/xorm"
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddCrossReferenceColumns(x *xorm.Engine) error {
|
||||
func AddCrossReferenceColumns(x db.EngineMigration) error {
|
||||
// Comment see models/comment.go
|
||||
type Comment struct {
|
||||
RefRepoID int64 `xorm:"index"`
|
||||
|
||||
@@ -6,13 +6,12 @@ package v1_10
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func DeleteOrphanedAttachments(x *xorm.Engine) error {
|
||||
func DeleteOrphanedAttachments(x db.EngineMigration) error {
|
||||
type Attachment struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
UUID string `xorm:"uuid UNIQUE"`
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "xorm.io/xorm"
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddRepoAdminChangeTeamAccessColumnForUser(x *xorm.Engine) error {
|
||||
func AddRepoAdminChangeTeamAccessColumnForUser(x db.EngineMigration) error {
|
||||
type User struct {
|
||||
RepoAdminChangeTeamAccess bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
package v1_10
|
||||
|
||||
import "xorm.io/xorm"
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddOriginalAuthorOnMigratedReleases(x *xorm.Engine) error {
|
||||
func AddOriginalAuthorOnMigratedReleases(x db.EngineMigration) error {
|
||||
type Release struct {
|
||||
ID int64
|
||||
OriginalAuthor string
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
package v1_10
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddTaskTable(x *xorm.Engine) error {
|
||||
func AddTaskTable(x db.EngineMigration) error {
|
||||
// TaskType defines task type
|
||||
type TaskType int
|
||||
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func DropColumnHeadUserNameOnPullRequest(x *xorm.Engine) error {
|
||||
func DropColumnHeadUserNameOnPullRequest(x db.EngineMigration) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Begin(); err != nil {
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddWhitelistDeployKeysToBranches(x *xorm.Engine) error {
|
||||
func AddWhitelistDeployKeysToBranches(x db.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
ID int64
|
||||
WhitelistDeployKeys bool `xorm:"NOT NULL DEFAULT false"`
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func RemoveLabelUneededCols(x *xorm.Engine) error {
|
||||
func RemoveLabelUneededCols(x db.EngineMigration) error {
|
||||
// Make sure the columns exist before dropping them
|
||||
type Label struct {
|
||||
QueryString string
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddTeamIncludesAllRepositories(x *xorm.Engine) error {
|
||||
func AddTeamIncludesAllRepositories(x db.EngineMigration) error {
|
||||
type Team struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
IncludesAllRepositories bool `xorm:"NOT NULL DEFAULT false"`
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
// RepoWatchMode specifies what kind of watch the user has on a repository
|
||||
type RepoWatchMode int8
|
||||
@@ -16,7 +14,7 @@ type Watch struct {
|
||||
Mode RepoWatchMode `xorm:"SMALLINT NOT NULL DEFAULT 1"`
|
||||
}
|
||||
|
||||
func AddModeColumnToWatch(x *xorm.Engine) error {
|
||||
func AddModeColumnToWatch(x db.EngineMigration) error {
|
||||
if err := x.Sync(new(Watch)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddTemplateToRepo(x *xorm.Engine) error {
|
||||
func AddTemplateToRepo(x db.EngineMigration) error {
|
||||
type Repository struct {
|
||||
IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"`
|
||||
TemplateID int64 `xorm:"INDEX"`
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddCommentIDOnNotification(x *xorm.Engine) error {
|
||||
func AddCommentIDOnNotification(x db.EngineMigration) error {
|
||||
type Notification struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
CommentID int64
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddCanCreateOrgRepoColumnForTeam(x *xorm.Engine) error {
|
||||
func AddCanCreateOrgRepoColumnForTeam(x db.EngineMigration) error {
|
||||
type Team struct {
|
||||
CanCreateOrgRepo bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func ChangeReviewContentToText(x *xorm.Engine) error {
|
||||
func ChangeReviewContentToText(x db.EngineMigration) error {
|
||||
switch x.Dialect().URI().DBType {
|
||||
case schemas.MYSQL:
|
||||
_, err := x.Exec("ALTER TABLE review MODIFY COLUMN content TEXT")
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddBranchProtectionCanPushAndEnableWhitelist(x *xorm.Engine) error {
|
||||
func AddBranchProtectionCanPushAndEnableWhitelist(x db.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
CanPush bool `xorm:"NOT NULL DEFAULT false"`
|
||||
EnableApprovalsWhitelist bool `xorm:"NOT NULL DEFAULT false"`
|
||||
@@ -132,7 +132,7 @@ func AddBranchProtectionCanPushAndEnableWhitelist(x *xorm.Engine) error {
|
||||
}
|
||||
|
||||
// getUserRepoPermission static function based on issues_model.IsOfficialReviewer at 5d78792385
|
||||
getUserRepoPermission := func(sess *xorm.Session, repo *Repository, user *User) (Permission, error) {
|
||||
getUserRepoPermission := func(sess db.Session, repo *Repository, user *User) (Permission, error) {
|
||||
var perm Permission
|
||||
|
||||
repoOwner := new(User)
|
||||
@@ -305,7 +305,7 @@ func AddBranchProtectionCanPushAndEnableWhitelist(x *xorm.Engine) error {
|
||||
}
|
||||
|
||||
// isOfficialReviewer static function based on 5d78792385
|
||||
isOfficialReviewer := func(sess *xorm.Session, issueID int64, reviewer *User) (bool, error) {
|
||||
isOfficialReviewer := func(sess db.Session, issueID int64, reviewer *User) (bool, error) {
|
||||
pr := new(PullRequest)
|
||||
has, err := sess.ID(issueID).Get(pr)
|
||||
if err != nil {
|
||||
|
||||
@@ -6,15 +6,15 @@ package v1_11
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func RemoveAttachmentMissedRepo(x *xorm.Engine) error {
|
||||
func RemoveAttachmentMissedRepo(x db.EngineMigration) error {
|
||||
type Attachment struct {
|
||||
UUID string `xorm:"uuid"`
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_11
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func FeatureChangeTargetBranch(x *xorm.Engine) error {
|
||||
func FeatureChangeTargetBranch(x db.EngineMigration) error {
|
||||
type Comment struct {
|
||||
OldRef string
|
||||
NewRef string
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_11
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func SanitizeOriginalURL(x *xorm.Engine) error {
|
||||
func SanitizeOriginalURL(x db.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64
|
||||
OriginalURL string `xorm:"VARCHAR(2048)"`
|
||||
|
||||
@@ -12,15 +12,14 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func RenameExistingUserAvatarName(x *xorm.Engine) error {
|
||||
func RenameExistingUserAvatarName(x db.EngineMigration) error {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_11
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func ExtendTrackedTimes(x *xorm.Engine) error {
|
||||
func ExtendTrackedTimes(x db.EngineMigration) error {
|
||||
type TrackedTime struct {
|
||||
Time int64 `xorm:"NOT NULL"`
|
||||
Deleted bool `xorm:"NOT NULL DEFAULT false"`
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddBlockOnRejectedReviews(x *xorm.Engine) error {
|
||||
func AddBlockOnRejectedReviews(x db.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
BlockOnRejectedReviews bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddReviewCommitAndStale(x *xorm.Engine) error {
|
||||
func AddReviewCommitAndStale(x db.EngineMigration) error {
|
||||
type Review struct {
|
||||
CommitID string `xorm:"VARCHAR(40)"`
|
||||
Stale bool `xorm:"NOT NULL DEFAULT false"`
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func FixMigratedRepositoryServiceType(x *xorm.Engine) error {
|
||||
func FixMigratedRepositoryServiceType(x db.EngineMigration) error {
|
||||
// structs.GithubService:
|
||||
// GithubService = 2
|
||||
_, err := x.Exec("UPDATE repository SET original_service_type = ? WHERE original_url LIKE 'https://github.com/%'", 2)
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddOwnerNameOnRepository(x *xorm.Engine) error {
|
||||
func AddOwnerNameOnRepository(x db.EngineMigration) error {
|
||||
type Repository struct {
|
||||
OwnerName string
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import "xorm.io/xorm"
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddIsRestricted(x *xorm.Engine) error {
|
||||
func AddIsRestricted(x db.EngineMigration) error {
|
||||
// User see models/user.go
|
||||
type User struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddRequireSignedCommits(x *xorm.Engine) error {
|
||||
func AddRequireSignedCommits(x db.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
RequireSignedCommits bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddReactionOriginals(x *xorm.Engine) error {
|
||||
func AddReactionOriginals(x db.EngineMigration) error {
|
||||
type Reaction struct {
|
||||
OriginalAuthorID int64 `xorm:"INDEX NOT NULL DEFAULT(0)"`
|
||||
OriginalAuthor string
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddUserRepoMissingColumns(x *xorm.Engine) error {
|
||||
func AddUserRepoMissingColumns(x db.EngineMigration) error {
|
||||
type VisibleType int
|
||||
type User struct {
|
||||
PasswdHashAlgo string `xorm:"NOT NULL DEFAULT 'pbkdf2'"`
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_12
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddReviewMigrateInfo(x *xorm.Engine) error {
|
||||
func AddReviewMigrateInfo(x db.EngineMigration) error {
|
||||
type Review struct {
|
||||
OriginalAuthor string
|
||||
OriginalAuthorID int64
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func FixTopicRepositoryCount(x *xorm.Engine) error {
|
||||
func FixTopicRepositoryCount(x db.EngineMigration) error {
|
||||
_, err := x.Exec(builder.Delete(builder.NotIn("`repo_id`", builder.Select("`id`").From("`repository`"))).From("`repo_topic`"))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -6,12 +6,11 @@ package v1_12
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddLanguageStats(x *xorm.Engine) error {
|
||||
func AddLanguageStats(x db.EngineMigration) error {
|
||||
// LanguageStat see models/repo_language_stats.go
|
||||
type LanguageStat struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
||||
@@ -11,15 +11,14 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/git/gitcmd"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func FixMergeBase(ctx context.Context, x *xorm.Engine) error {
|
||||
func FixMergeBase(ctx context.Context, x db.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
OwnerID int64 `xorm:"UNIQUE(s) index"`
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func PurgeUnusedDependencies(x *xorm.Engine) error {
|
||||
func PurgeUnusedDependencies(x db.EngineMigration) error {
|
||||
if _, err := x.Exec("DELETE FROM issue_dependency WHERE issue_id NOT IN (SELECT id FROM issue)"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func ExpandWebhooks(x *xorm.Engine) error {
|
||||
func ExpandWebhooks(x db.EngineMigration) error {
|
||||
type HookEvents struct {
|
||||
Create bool `json:"create"`
|
||||
Delete bool `json:"delete"`
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_12
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddSystemWebhookColumn(x *xorm.Engine) error {
|
||||
func AddSystemWebhookColumn(x db.EngineMigration) error {
|
||||
type Webhook struct {
|
||||
IsSystemWebhook bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_12
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddBranchProtectionProtectedFilesColumn(x *xorm.Engine) error {
|
||||
func AddBranchProtectionProtectedFilesColumn(x db.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
ProtectedFilePatterns string `xorm:"TEXT"`
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import "xorm.io/xorm"
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddEmailHashTable(x *xorm.Engine) error {
|
||||
func AddEmailHashTable(x db.EngineMigration) error {
|
||||
// EmailHash represents a pre-generated hash map
|
||||
type EmailHash struct {
|
||||
Hash string `xorm:"pk varchar(32)"`
|
||||
|
||||
@@ -11,14 +11,13 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/git/gitcmd"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func RefixMergeBase(ctx context.Context, x *xorm.Engine) error {
|
||||
func RefixMergeBase(ctx context.Context, x db.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
OwnerID int64 `xorm:"UNIQUE(s) index"`
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_12
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddOrgIDLabelColumn(x *xorm.Engine) error {
|
||||
func AddOrgIDLabelColumn(x db.EngineMigration) error {
|
||||
type Label struct {
|
||||
OrgID int64 `xorm:"INDEX"`
|
||||
}
|
||||
|
||||
@@ -8,16 +8,15 @@ import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/modules/gitrepo"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddCommitDivergenceToPulls(x *xorm.Engine) error {
|
||||
func AddCommitDivergenceToPulls(x db.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
OwnerID int64 `xorm:"UNIQUE(s) index"`
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddBlockOnOutdatedBranch(x *xorm.Engine) error {
|
||||
func AddBlockOnOutdatedBranch(x db.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
BlockOnOutdatedBranch bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_12
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddResolveDoerIDCommentColumn(x *xorm.Engine) error {
|
||||
func AddResolveDoerIDCommentColumn(x db.EngineMigration) error {
|
||||
type Comment struct {
|
||||
ResolveDoerID int64
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
package v1_12
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func PrependRefsHeadsToIssueRefs(x *xorm.Engine) error {
|
||||
func PrependRefsHeadsToIssueRefs(x db.EngineMigration) error {
|
||||
var query string
|
||||
|
||||
switch {
|
||||
|
||||
@@ -6,13 +6,12 @@ package v1_13
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func FixLanguageStatsToSaveSize(x *xorm.Engine) error {
|
||||
func FixLanguageStatsToSaveSize(x db.EngineMigration) error {
|
||||
// LanguageStat see models/repo_language_stats.go
|
||||
type LanguageStat struct {
|
||||
Size int64 `xorm:"NOT NULL DEFAULT 0"`
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_13
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddKeepActivityPrivateUserColumn(x *xorm.Engine) error {
|
||||
func AddKeepActivityPrivateUserColumn(x db.EngineMigration) error {
|
||||
type User struct {
|
||||
KeepActivityPrivate bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func SetIsArchivedToFalse(x *xorm.Engine) error {
|
||||
func SetIsArchivedToFalse(x db.EngineMigration) error {
|
||||
type Repository struct {
|
||||
IsArchived bool `xorm:"INDEX"`
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func RecalculateStars(x *xorm.Engine) (err error) {
|
||||
func RecalculateStars(x db.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,13 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func UpdateMatrixWebhookHTTPMethod(x *xorm.Engine) error {
|
||||
func UpdateMatrixWebhookHTTPMethod(x db.EngineMigration) error {
|
||||
matrixHookTaskType := 9 // value comes from the models package
|
||||
type Webhook struct {
|
||||
HTTPMethod string
|
||||
|
||||
@@ -6,12 +6,11 @@ package v1_13
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func IncreaseLanguageField(x *xorm.Engine) error {
|
||||
func IncreaseLanguageField(x db.EngineMigration) error {
|
||||
type LanguageStat struct {
|
||||
RepoID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
|
||||
Language string `xorm:"VARCHAR(50) UNIQUE(s) INDEX NOT NULL"`
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddProjectsInfo(x *xorm.Engine) error {
|
||||
func AddProjectsInfo(x db.EngineMigration) error {
|
||||
// Create new tables
|
||||
type (
|
||||
ProjectType uint8
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func CreateReviewsForCodeComments(x *xorm.Engine) error {
|
||||
func CreateReviewsForCodeComments(x db.EngineMigration) error {
|
||||
// Review
|
||||
type Review struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func PurgeInvalidDependenciesComments(x *xorm.Engine) error {
|
||||
func PurgeInvalidDependenciesComments(x db.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
|
||||
}
|
||||
|
||||
@@ -6,12 +6,11 @@ package v1_13
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddCreatedAndUpdatedToMilestones(x *xorm.Engine) error {
|
||||
func AddCreatedAndUpdatedToMilestones(x db.EngineMigration) error {
|
||||
type Milestone struct {
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddPrimaryKeyToRepoTopic(x *xorm.Engine) error {
|
||||
func AddPrimaryKeyToRepoTopic(x db.EngineMigration) error {
|
||||
// Topic represents a topic of repositories
|
||||
type Topic struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
||||
@@ -9,14 +9,14 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func SetDefaultPasswordToArgon2(x *xorm.Engine) error {
|
||||
func SetDefaultPasswordToArgon2(x db.EngineMigration) error {
|
||||
switch {
|
||||
case setting.Database.Type.IsMySQL():
|
||||
_, err := x.Exec("ALTER TABLE `user` ALTER passwd_hash_algo SET DEFAULT 'argon2';")
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
package v1_13
|
||||
|
||||
import "xorm.io/xorm"
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddTrustModelToRepository(x *xorm.Engine) error {
|
||||
func AddTrustModelToRepository(x db.EngineMigration) error {
|
||||
type Repository struct {
|
||||
TrustModel int
|
||||
}
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddTeamReviewRequestSupport(x *xorm.Engine) error {
|
||||
func AddTeamReviewRequestSupport(x db.EngineMigration) error {
|
||||
type Review struct {
|
||||
ReviewerTeamID int64 `xorm:"NOT NULL DEFAULT 0"`
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
package v1_13
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddTimeStamps(x *xorm.Engine) error {
|
||||
func AddTimeStamps(x db.EngineMigration) error {
|
||||
// this will add timestamps where it is useful to have
|
||||
|
||||
// Star represents a starred repo by an user.
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_14
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddChangedProtectedFilesPullRequestColumn(x *xorm.Engine) error {
|
||||
func AddChangedProtectedFilesPullRequestColumn(x db.EngineMigration) error {
|
||||
type PullRequest struct {
|
||||
ChangedProtectedFiles []string `xorm:"TEXT JSON"`
|
||||
}
|
||||
|
||||
@@ -9,11 +9,10 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
// Copy paste from models/repo.go because we cannot import models package
|
||||
@@ -25,7 +24,7 @@ func userPath(userName string) string {
|
||||
return filepath.Join(setting.RepoRootPath, strings.ToLower(userName))
|
||||
}
|
||||
|
||||
func FixPublisherIDforTagReleases(ctx context.Context, x *xorm.Engine) error {
|
||||
func FixPublisherIDforTagReleases(ctx context.Context, x db.EngineMigration) error {
|
||||
type Release struct {
|
||||
ID int64
|
||||
RepoID int64
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func FixRepoTopics(x *xorm.Engine) error {
|
||||
func FixRepoTopics(x db.EngineMigration) error {
|
||||
type Repository struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Topics []string `xorm:"TEXT JSON"`
|
||||
|
||||
@@ -7,13 +7,12 @@ import (
|
||||
"errors"
|
||||
"strconv"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func UpdateCodeCommentReplies(x *xorm.Engine) error {
|
||||
func UpdateCodeCommentReplies(x db.EngineMigration) error {
|
||||
type Comment struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
CommitSHA string `xorm:"VARCHAR(40)"`
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func UpdateReactionConstraint(x *xorm.Engine) error {
|
||||
func UpdateReactionConstraint(x db.EngineMigration) error {
|
||||
// Reaction represents a reactions on issues and comments.
|
||||
type Reaction struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddBlockOnOfficialReviewRequests(x *xorm.Engine) error {
|
||||
func AddBlockOnOfficialReviewRequests(x db.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
BlockOnOfficialReviewRequests bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -6,12 +6,11 @@ package v1_14
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func ConvertTaskTypeToString(x *xorm.Engine) error {
|
||||
func ConvertTaskTypeToString(x db.EngineMigration) error {
|
||||
const (
|
||||
GOGS int = iota + 1
|
||||
SLACK
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func ConvertWebhookTaskTypeToString(x *xorm.Engine) error {
|
||||
func ConvertWebhookTaskTypeToString(x db.EngineMigration) error {
|
||||
const (
|
||||
GOGS int = iota + 1
|
||||
SLACK
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func ConvertTopicNameFrom25To50(x *xorm.Engine) error {
|
||||
func ConvertTopicNameFrom25To50(x db.EngineMigration) error {
|
||||
type Topic struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Name string `xorm:"UNIQUE VARCHAR(50)"`
|
||||
|
||||
@@ -6,7 +6,7 @@ package v1_14
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
// OAuth2Grant here is a snapshot of models.OAuth2Grant for this version
|
||||
@@ -29,7 +29,7 @@ func (grant *OAuth2Grant) TableName() string {
|
||||
return "oauth2_grant"
|
||||
}
|
||||
|
||||
func AddScopeAndNonceColumnsToOAuth2Grant(x *xorm.Engine) error {
|
||||
func AddScopeAndNonceColumnsToOAuth2Grant(x db.EngineMigration) error {
|
||||
if err := x.Sync(new(OAuth2Grant)); err != nil {
|
||||
return fmt.Errorf("Sync: %w", err)
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func ConvertHookTaskTypeToVarcharAndTrim(x *xorm.Engine) error {
|
||||
func ConvertHookTaskTypeToVarcharAndTrim(x db.EngineMigration) error {
|
||||
dbType := x.Dialect().URI().DBType
|
||||
if dbType == schemas.SQLITE { // For SQLITE, varchar or char will always be represented as TEXT
|
||||
return nil
|
||||
|
||||
@@ -7,15 +7,16 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
|
||||
"golang.org/x/crypto/argon2"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"golang.org/x/crypto/pbkdf2"
|
||||
"golang.org/x/crypto/scrypt"
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func RecalculateUserEmptyPWD(x *xorm.Engine) (err error) {
|
||||
func RecalculateUserEmptyPWD(x db.EngineMigration) (err error) {
|
||||
const (
|
||||
algoBcrypt = "bcrypt"
|
||||
algoScrypt = "scrypt"
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_14
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddUserRedirect(x *xorm.Engine) (err error) {
|
||||
func AddUserRedirect(x db.EngineMigration) (err error) {
|
||||
type UserRedirect struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
package v1_14
|
||||
|
||||
import "xorm.io/xorm"
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func RecreateUserTableToFixDefaultValues(_ *xorm.Engine) error {
|
||||
func RecreateUserTableToFixDefaultValues(_ db.EngineMigration) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func CommentTypeDeleteBranchUseOldRef(x *xorm.Engine) error {
|
||||
func CommentTypeDeleteBranchUseOldRef(x db.EngineMigration) error {
|
||||
_, err := x.Exec("UPDATE comment SET old_ref = commit_sha, commit_sha = '' WHERE type = 11")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_14
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddDismissedReviewColumn(x *xorm.Engine) error {
|
||||
func AddDismissedReviewColumn(x db.EngineMigration) error {
|
||||
type Review struct {
|
||||
Dismissed bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_14
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddSortingColToProjectBoard(x *xorm.Engine) error {
|
||||
func AddSortingColToProjectBoard(x db.EngineMigration) error {
|
||||
type ProjectBoard struct {
|
||||
Sorting int8 `xorm:"NOT NULL DEFAULT 0"`
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddSessionTable(x *xorm.Engine) error {
|
||||
func AddSessionTable(x db.EngineMigration) error {
|
||||
type Session struct {
|
||||
Key string `xorm:"pk CHAR(16)"`
|
||||
Data []byte `xorm:"BLOB"`
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_14
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddTimeIDCommentColumn(x *xorm.Engine) error {
|
||||
func AddTimeIDCommentColumn(x db.EngineMigration) error {
|
||||
type Comment struct {
|
||||
TimeID int64
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_14
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddRepoTransfer(x *xorm.Engine) error {
|
||||
func AddRepoTransfer(x db.EngineMigration) error {
|
||||
type RepoTransfer struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
DoerID int64
|
||||
|
||||
@@ -7,13 +7,12 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func FixPostgresIDSequences(x *xorm.Engine) error {
|
||||
func FixPostgresIDSequences(x db.EngineMigration) error {
|
||||
if !setting.Database.Type.IsPostgreSQL() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,14 +3,12 @@
|
||||
|
||||
package v1_14
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
// 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 *xorm.Engine) error {
|
||||
func RemoveInvalidLabels(x db.EngineMigration) error {
|
||||
type Comment struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Type int `xorm:"INDEX"`
|
||||
|
||||
@@ -6,11 +6,11 @@ package v1_14
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
// DeleteOrphanedIssueLabels looks through the database for issue_labels where the label no longer exists and deletes them.
|
||||
func DeleteOrphanedIssueLabels(x *xorm.Engine) error {
|
||||
func DeleteOrphanedIssueLabels(x db.EngineMigration) error {
|
||||
type IssueLabel struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
IssueID int64 `xorm:"UNIQUE(s)"`
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_15
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddLFSMirrorColumns(x *xorm.Engine) error {
|
||||
func AddLFSMirrorColumns(x db.EngineMigration) error {
|
||||
type Mirror struct {
|
||||
LFS bool `xorm:"lfs_enabled NOT NULL DEFAULT false"`
|
||||
LFSEndpoint string `xorm:"lfs_endpoint TEXT"`
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
package v1_15
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func ConvertAvatarURLToText(x *xorm.Engine) error {
|
||||
func ConvertAvatarURLToText(x db.EngineMigration) error {
|
||||
dbType := x.Dialect().URI().DBType
|
||||
if dbType == schemas.SQLITE { // For SQLITE, varchar or char will always be represented as TEXT
|
||||
return nil
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
package v1_15
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func DeleteMigrationCredentials(x *xorm.Engine) (err error) {
|
||||
func DeleteMigrationCredentials(x db.EngineMigration) (err error) {
|
||||
// Task represents a task
|
||||
type Task struct {
|
||||
ID int64
|
||||
|
||||
@@ -6,10 +6,10 @@ package v1_15
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
)
|
||||
|
||||
func AddPrimaryEmail2EmailAddress(x *xorm.Engine) error {
|
||||
func AddPrimaryEmail2EmailAddress(x db.EngineMigration) error {
|
||||
type User struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Email string `xorm:"NOT NULL"`
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
package v1_15
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
import "code.gitea.io/gitea/models/db"
|
||||
|
||||
func AddIssueResourceIndexTable(x *xorm.Engine) error {
|
||||
func AddIssueResourceIndexTable(x db.EngineMigration) error {
|
||||
type ResourceIndex struct {
|
||||
GroupID int64 `xorm:"pk"`
|
||||
MaxIndex int64 `xorm:"index"`
|
||||
|
||||
@@ -7,12 +7,11 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func CreatePushMirrorTable(x *xorm.Engine) error {
|
||||
func CreatePushMirrorTable(x db.EngineMigration) error {
|
||||
type PushMirror struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RepoID int64 `xorm:"INDEX"`
|
||||
|
||||
@@ -7,13 +7,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations/base"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func RenameTaskErrorsToMessage(x *xorm.Engine) error {
|
||||
func RenameTaskErrorsToMessage(x db.EngineMigration) error {
|
||||
type Task struct {
|
||||
Errors string `xorm:"TEXT"` // if task failed, saved the error reason
|
||||
Type int
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user