summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorDavid Schneiderbauer <daviian@users.noreply.github.com>2017-09-28 15:14:51 +0200
committerLauris BH <lauris@nix.lv>2017-09-28 16:14:51 +0300
commit26e49b8e3d8cdcb8d9168e4d25802bcfeb9dc077 (patch)
treeca59c70084be802ba23cdb299fef95dc697be71c /models
parentcc84ca40d787d853186af6c16d328daa37d543da (diff)
downloadgitea-26e49b8e3d8cdcb8d9168e4d25802bcfeb9dc077.tar.gz
gitea-26e49b8e3d8cdcb8d9168e4d25802bcfeb9dc077.zip
Fix doubled issue tab introduced in migration v16 (#2611)
* fix duplicate issue tab as UnitTypeIssue and UnitTypeExternalTracker are existing at the same time Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com>
Diffstat (limited to 'models')
-rw-r--r--models/migrations/migrations.go2
-rw-r--r--models/migrations/v44.go69
2 files changed, 71 insertions, 0 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 95b8e0774f..c2cd7568af 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -136,6 +136,8 @@ var migrations = []Migration{
NewMigration("add tags to releases and sync existing repositories", releaseAddColumnIsTagAndSyncTags),
// v43 -> v44
NewMigration("fix protected branch can push value to false", fixProtectedBranchCanPushValue),
+ // v44 -> v45
+ NewMigration("remove duplicate unit types", removeDuplicateUnitTypes),
}
// Migrate database to current version
diff --git a/models/migrations/v44.go b/models/migrations/v44.go
new file mode 100644
index 0000000000..4de3ad4e99
--- /dev/null
+++ b/models/migrations/v44.go
@@ -0,0 +1,69 @@
+// Copyright 2017 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 migrations
+
+import (
+ "fmt"
+
+ "github.com/go-xorm/xorm"
+)
+
+func removeDuplicateUnitTypes(x *xorm.Engine) error {
+ // RepoUnit describes all units of a repository
+ type RepoUnit struct {
+ RepoID int64
+ Type int
+ }
+
+ // Enumerate all the unit types
+ const (
+ UnitTypeCode = iota + 1 // 1 code
+ UnitTypeIssues // 2 issues
+ UnitTypePullRequests // 3 PRs
+ UnitTypeReleases // 4 Releases
+ UnitTypeWiki // 5 Wiki
+ UnitTypeExternalWiki // 6 ExternalWiki
+ UnitTypeExternalTracker // 7 ExternalTracker
+ )
+
+ var externalIssueRepoUnits []RepoUnit
+ err := x.Where("type = ?", UnitTypeExternalTracker).Find(&externalIssueRepoUnits)
+ if err != nil {
+ return fmt.Errorf("Query repositories: %v", err)
+ }
+
+ var externalWikiRepoUnits []RepoUnit
+ err = x.Where("type = ?", UnitTypeExternalWiki).Find(&externalWikiRepoUnits)
+ if err != nil {
+ return fmt.Errorf("Query repositories: %v", err)
+ }
+
+ sess := x.NewSession()
+ defer sess.Close()
+
+ if err := sess.Begin(); err != nil {
+ return err
+ }
+
+ for _, repoUnit := range externalIssueRepoUnits {
+ if _, err = sess.Delete(&RepoUnit{
+ RepoID: repoUnit.RepoID,
+ Type: UnitTypeIssues,
+ }); err != nil {
+ return fmt.Errorf("Delete repo unit: %v", err)
+ }
+ }
+
+ for _, repoUnit := range externalWikiRepoUnits {
+ if _, err = sess.Delete(&RepoUnit{
+ RepoID: repoUnit.RepoID,
+ Type: UnitTypeWiki,
+ }); err != nil {
+ return fmt.Errorf("Delete repo unit: %v", err)
+ }
+ }
+
+ return sess.Commit()
+}