1- // Copyright 2017 The Gitea Authors. All rights reserved.
1+ // Copyright 2018 The Gitea Authors. All rights reserved.
22// Use of this source code is governed by a MIT-style
33// license that can be found in the LICENSE file.
44
@@ -7,51 +7,17 @@ package migrations
77import (
88 "fmt"
99
10- "code.gitea.io/gitea/modules/util"
11-
10+ "code.gitea.io/gitea/models"
1211 "github.com/go-xorm/xorm"
1312)
1413
15- func addPullRequestOptions (x * xorm.Engine ) error {
16- // RepoUnit describes all units of a repository
17- type RepoUnit struct {
18- ID int64
19- RepoID int64 `xorm:"INDEX(s)"`
20- Type int `xorm:"INDEX(s)"`
21- Config map [string ]interface {} `xorm:"JSON"`
22- CreatedUnix util.TimeStamp `xorm:"INDEX CREATED"`
23- }
24-
25- sess := x .NewSession ()
26- defer sess .Close ()
27- if err := sess .Begin (); err != nil {
28- return err
14+ func addModeToDeploKeys (x * xorm.Engine ) error {
15+ type DeployKey struct {
16+ Mode models.AccessMode `xorm:"NOT NULL DEFAULT 1"`
2917 }
3018
31- //Updating existing issue units
32- units := make ([]* RepoUnit , 0 , 100 )
33- if err := sess .Where ("`type` = ?" , V16UnitTypePRs ).Find (& units ); err != nil {
34- return fmt .Errorf ("Query repo units: %v" , err )
35- }
36- for _ , unit := range units {
37- if unit .Config == nil {
38- unit .Config = make (map [string ]interface {})
39- }
40- if _ , ok := unit .Config ["IgnoreWhitespaceConflicts" ]; ! ok {
41- unit .Config ["IgnoreWhitespaceConflicts" ] = false
42- }
43- if _ , ok := unit .Config ["AllowMerge" ]; ! ok {
44- unit .Config ["AllowMerge" ] = true
45- }
46- if _ , ok := unit .Config ["AllowRebase" ]; ! ok {
47- unit .Config ["AllowRebase" ] = true
48- }
49- if _ , ok := unit .Config ["AllowSquash" ]; ! ok {
50- unit .Config ["AllowSquash" ] = true
51- }
52- if _ , err := sess .ID (unit .ID ).Cols ("config" ).Update (unit ); err != nil {
53- return err
54- }
19+ if err := x .Sync2 (new (DeployKey )); err != nil {
20+ return fmt .Errorf ("Sync2: %v" , err )
5521 }
56- return sess . Commit ()
22+ return nil
5723}
0 commit comments