summaryrefslogtreecommitdiffstats
path: root/models/migrations
diff options
context:
space:
mode:
authorDavid Schneiderbauer <daviian@users.noreply.github.com>2018-06-21 18:00:13 +0200
committertechknowlogick <techknowlogick@users.noreply.github.com>2018-06-21 12:00:13 -0400
commit0b3ea428477b9da33f40252e79aafe85b09526f3 (patch)
tree4fccc7dbf7f027331735d7d041bc290db632b744 /models/migrations
parent46d19c4676efe5201c5de790bcb963bfc93a95c7 (diff)
downloadgitea-0b3ea428477b9da33f40252e79aafe85b09526f3.tar.gz
gitea-0b3ea428477b9da33f40252e79aafe85b09526f3.zip
hide issues from org private repos w/o team assignment (#4034)
Diffstat (limited to 'models/migrations')
-rw-r--r--models/migrations/migrations.go2
-rw-r--r--models/migrations/v38.go9
-rw-r--r--models/migrations/v69.go80
3 files changed, 89 insertions, 2 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 7732e17094..cc262d8102 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -190,6 +190,8 @@ var migrations = []Migration{
NewMigration("remove stale watches", removeStaleWatches),
// v68 -> V69
NewMigration("Reformat and remove incorrect topics", reformatAndRemoveIncorrectTopics),
+ // v69 -> v70
+ NewMigration("move team units to team_unit table", moveTeamUnitsToTeamUnitTable),
}
// Migrate database to current version
diff --git a/models/migrations/v38.go b/models/migrations/v38.go
index 6f66484b05..eb90f9fbff 100644
--- a/models/migrations/v38.go
+++ b/models/migrations/v38.go
@@ -25,10 +25,15 @@ func removeCommitsUnitType(x *xorm.Engine) (err error) {
Created time.Time `xorm:"-"`
}
+ type Team struct {
+ ID int64
+ UnitTypes []int `xorm:"json"`
+ }
+
// Update team unit types
const batchSize = 100
for start := 0; ; start += batchSize {
- teams := make([]*models.Team, 0, batchSize)
+ teams := make([]*Team, 0, batchSize)
if err := x.Limit(batchSize, start).Find(&teams); err != nil {
return err
}
@@ -36,7 +41,7 @@ func removeCommitsUnitType(x *xorm.Engine) (err error) {
break
}
for _, team := range teams {
- ut := make([]models.UnitType, 0, len(team.UnitTypes))
+ ut := make([]int, 0, len(team.UnitTypes))
for _, u := range team.UnitTypes {
if u < V16UnitTypeCommits {
ut = append(ut, u)
diff --git a/models/migrations/v69.go b/models/migrations/v69.go
new file mode 100644
index 0000000000..8d964688ae
--- /dev/null
+++ b/models/migrations/v69.go
@@ -0,0 +1,80 @@
+// 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 migrations
+
+import (
+ "fmt"
+
+ "github.com/go-xorm/xorm"
+)
+
+func moveTeamUnitsToTeamUnitTable(x *xorm.Engine) error {
+ // Team see models/team.go
+ type Team struct {
+ ID int64
+ OrgID int64
+ UnitTypes []int `xorm:"json"`
+ }
+
+ // TeamUnit see models/org_team.go
+ type TeamUnit struct {
+ ID int64 `xorm:"pk autoincr"`
+ OrgID int64 `xorm:"INDEX"`
+ TeamID int64 `xorm:"UNIQUE(s)"`
+ Type int `xorm:"UNIQUE(s)"`
+ }
+
+ if err := x.Sync2(new(TeamUnit)); err != nil {
+ return fmt.Errorf("Sync2: %v", err)
+ }
+
+ sess := x.NewSession()
+ defer sess.Close()
+
+ if err := sess.Begin(); err != nil {
+ return err
+ }
+
+ // Update team unit types
+ const batchSize = 100
+ for start := 0; ; start += batchSize {
+ teams := make([]*Team, 0, batchSize)
+ if err := x.Limit(batchSize, start).Find(&teams); err != nil {
+ return err
+ }
+ if len(teams) == 0 {
+ break
+ }
+
+ for _, team := range teams {
+ var unitTypes []int
+ if len(team.UnitTypes) == 0 {
+ unitTypes = allUnitTypes
+ } else {
+ unitTypes = team.UnitTypes
+ }
+
+ // insert units for team
+ var units = make([]TeamUnit, 0, len(unitTypes))
+ for _, tp := range unitTypes {
+ units = append(units, TeamUnit{
+ OrgID: team.OrgID,
+ TeamID: team.ID,
+ Type: tp,
+ })
+ }
+
+ if _, err := sess.Insert(&units); err != nil {
+ return fmt.Errorf("Insert team units: %v", err)
+ }
+
+ }
+ }
+
+ if err := dropTableColumns(sess, "team", "unit_types"); err != nil {
+ return err
+ }
+ return sess.Commit()
+}