diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-11-02 16:54:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 16:54:36 +0800 |
commit | e72acd5e5b2d043fcf0a0182a1eedaed8120c155 (patch) | |
tree | 77e4c341bef6450e5dfa7a1f61c9693527a133d0 /models/migrations/v1_8 | |
parent | 4827f42f56bcc70d40e073a8502930d9cce39798 (diff) | |
download | gitea-e72acd5e5b2d043fcf0a0182a1eedaed8120c155.tar.gz gitea-e72acd5e5b2d043fcf0a0182a1eedaed8120c155.zip |
Split migrations folder (#21549)
There are too many files in `models/migrations` folder so that I split
them into sub folders.
Diffstat (limited to 'models/migrations/v1_8')
-rw-r--r-- | models/migrations/v1_8/v76.go | 75 | ||||
-rw-r--r-- | models/migrations/v1_8/v77.go | 17 | ||||
-rw-r--r-- | models/migrations/v1_8/v78.go | 44 | ||||
-rw-r--r-- | models/migrations/v1_8/v79.go | 26 | ||||
-rw-r--r-- | models/migrations/v1_8/v80.go | 17 | ||||
-rw-r--r-- | models/migrations/v1_8/v81.go | 31 |
6 files changed, 210 insertions, 0 deletions
diff --git a/models/migrations/v1_8/v76.go b/models/migrations/v1_8/v76.go new file mode 100644 index 0000000000..ef60eb7260 --- /dev/null +++ b/models/migrations/v1_8/v76.go @@ -0,0 +1,75 @@ +// Copyright 2018 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package v1_8 // nolint + +import ( + "fmt" + + "code.gitea.io/gitea/modules/timeutil" + + "xorm.io/xorm" +) + +func AddPullRequestRebaseWithMerge(x *xorm.Engine) error { + // RepoUnit describes all units of a repository + type RepoUnit struct { + ID int64 + RepoID int64 `xorm:"INDEX(s)"` + Type int `xorm:"INDEX(s)"` + Config map[string]interface{} `xorm:"JSON"` + CreatedUnix timeutil.TimeStamp `xorm:"INDEX CREATED"` + } + + const ( + v16UnitTypeCode = iota + 1 // 1 code + v16UnitTypeIssues // 2 issues + v16UnitTypePRs // 3 PRs + v16UnitTypeCommits // 4 Commits + v16UnitTypeReleases // 5 Releases + v16UnitTypeWiki // 6 Wiki + v16UnitTypeSettings // 7 Settings + v16UnitTypeExternalWiki // 8 ExternalWiki + v16UnitTypeExternalTracker // 9 ExternalTracker + ) + + sess := x.NewSession() + defer sess.Close() + if err := sess.Begin(); err != nil { + return err + } + + // Updating existing issue units + units := make([]*RepoUnit, 0, 100) + if err := sess.Where("`type` = ?", v16UnitTypePRs).Find(&units); err != nil { + return fmt.Errorf("Query repo units: %w", err) + } + for _, unit := range units { + if unit.Config == nil { + unit.Config = make(map[string]interface{}) + } + // Allow the new merge style if all other merge styles are allowed + allowMergeRebase := true + + if allowMerge, ok := unit.Config["AllowMerge"]; ok { + allowMergeRebase = allowMergeRebase && allowMerge.(bool) + } + + if allowRebase, ok := unit.Config["AllowRebase"]; ok { + allowMergeRebase = allowMergeRebase && allowRebase.(bool) + } + + if allowSquash, ok := unit.Config["AllowSquash"]; ok { + allowMergeRebase = allowMergeRebase && allowSquash.(bool) + } + + if _, ok := unit.Config["AllowRebaseMerge"]; !ok { + unit.Config["AllowRebaseMerge"] = allowMergeRebase + } + if _, err := sess.ID(unit.ID).Cols("config").Update(unit); err != nil { + return err + } + } + return sess.Commit() +} diff --git a/models/migrations/v1_8/v77.go b/models/migrations/v1_8/v77.go new file mode 100644 index 0000000000..7d5dccc9b6 --- /dev/null +++ b/models/migrations/v1_8/v77.go @@ -0,0 +1,17 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package v1_8 // nolint + +import ( + "xorm.io/xorm" +) + +func AddUserDefaultTheme(x *xorm.Engine) error { + type User struct { + Theme string `xorm:"VARCHAR(30) NOT NULL DEFAULT ''"` + } + + return x.Sync2(new(User)) +} diff --git a/models/migrations/v1_8/v78.go b/models/migrations/v1_8/v78.go new file mode 100644 index 0000000000..d7943fb0aa --- /dev/null +++ b/models/migrations/v1_8/v78.go @@ -0,0 +1,44 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package v1_8 // nolint + +import ( + "code.gitea.io/gitea/models/migrations/base" + + "xorm.io/xorm" +) + +func RenameRepoIsBareToIsEmpty(x *xorm.Engine) error { + type Repository struct { + ID int64 `xorm:"pk autoincr"` + IsBare bool + IsEmpty bool `xorm:"INDEX"` + } + + sess := x.NewSession() + defer sess.Close() + if err := sess.Begin(); err != nil { + return err + } + + if err := sess.Sync2(new(Repository)); err != nil { + return err + } + if _, err := sess.Exec("UPDATE repository SET is_empty = is_bare;"); err != nil { + return err + } + if err := sess.Commit(); err != nil { + return err + } + + if err := sess.Begin(); err != nil { + return err + } + if err := base.DropTableColumns(sess, "repository", "is_bare"); err != nil { + return err + } + + return sess.Commit() +} diff --git a/models/migrations/v1_8/v79.go b/models/migrations/v1_8/v79.go new file mode 100644 index 0000000000..6a867f5055 --- /dev/null +++ b/models/migrations/v1_8/v79.go @@ -0,0 +1,26 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package v1_8 // nolint + +import ( + "code.gitea.io/gitea/modules/setting" + + "xorm.io/xorm" +) + +func AddCanCloseIssuesViaCommitInAnyBranch(x *xorm.Engine) error { + type Repository struct { + ID int64 `xorm:"pk autoincr"` + CloseIssuesViaCommitInAnyBranch bool `xorm:"NOT NULL DEFAULT false"` + } + + if err := x.Sync2(new(Repository)); err != nil { + return err + } + + _, err := x.Exec("UPDATE repository SET close_issues_via_commit_in_any_branch = ?", + setting.Repository.DefaultCloseIssuesViaCommitsInAnyBranch) + return err +} diff --git a/models/migrations/v1_8/v80.go b/models/migrations/v1_8/v80.go new file mode 100644 index 0000000000..2e1b0631e1 --- /dev/null +++ b/models/migrations/v1_8/v80.go @@ -0,0 +1,17 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package v1_8 // nolint + +import "xorm.io/xorm" + +func AddIsLockedToIssues(x *xorm.Engine) error { + // Issue see models/issue.go + type Issue struct { + ID int64 `xorm:"pk autoincr"` + IsLocked bool `xorm:"NOT NULL DEFAULT false"` + } + + return x.Sync2(new(Issue)) +} diff --git a/models/migrations/v1_8/v81.go b/models/migrations/v1_8/v81.go new file mode 100644 index 0000000000..b06f879ef5 --- /dev/null +++ b/models/migrations/v1_8/v81.go @@ -0,0 +1,31 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package v1_8 // nolint + +import ( + "fmt" + + "xorm.io/xorm" + "xorm.io/xorm/schemas" +) + +func ChangeU2FCounterType(x *xorm.Engine) error { + var err error + + switch x.Dialect().URI().DBType { + case schemas.MYSQL: + _, err = x.Exec("ALTER TABLE `u2f_registration` MODIFY `counter` BIGINT") + case schemas.POSTGRES: + _, err = x.Exec("ALTER TABLE `u2f_registration` ALTER COLUMN `counter` SET DATA TYPE bigint") + case schemas.MSSQL: + _, err = x.Exec("ALTER TABLE `u2f_registration` ALTER COLUMN `counter` BIGINT") + } + + if err != nil { + return fmt.Errorf("Error changing u2f_registration counter column type: %w", err) + } + + return nil +} |