Browse Source

Migration to fix existing owner team units (#1873)

Ethan Koenig 2 years ago
parent
commit
ca9169fbe9
2 changed files with 27 additions and 0 deletions
  1. 2 0
      models/migrations/migrations.go
  2. 25 0
      models/migrations/v34.go

+ 2 - 0
models/migrations/migrations.go

@@ -116,6 +116,8 @@ var migrations = []Migration{
116 116
 	NewMigration("add units for team", addUnitsToRepoTeam),
117 117
 	// v33 -> v34
118 118
 	NewMigration("remove columns from action", removeActionColumns),
119
+	// v34 -> v35
120
+	NewMigration("give all units to owner teams", giveAllUnitsToOwnerTeams),
119 121
 }
120 122
 
121 123
 // Migrate database to current version

+ 25 - 0
models/migrations/v34.go

@@ -0,0 +1,25 @@
1
+// Copyright 2017 Gitea. All rights reserved.
2
+// Use of this source code is governed by a MIT-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package migrations
6
+
7
+import (
8
+	"github.com/go-xorm/xorm"
9
+)
10
+
11
+// Team see models/team.go
12
+type Team struct {
13
+	UnitTypes []int `xorm:"json"`
14
+}
15
+
16
+const ownerAccessMode = 4
17
+
18
+var allUnitTypes = []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
19
+
20
+func giveAllUnitsToOwnerTeams(x *xorm.Engine) error {
21
+	_, err := x.Cols("unit_types").
22
+		Where("authorize = ?", ownerAccessMode).
23
+		Update(&Team{UnitTypes: allUnitTypes})
24
+	return err
25
+}