aboutsummaryrefslogtreecommitdiffstats
path: root/models/migrations/v39.go
diff options
context:
space:
mode:
authorDavid Schneiderbauer <daviian@users.noreply.github.com>2017-10-08 13:08:18 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2017-10-08 19:08:18 +0800
commitebac051e7207181ac3d7bbe288536bf2224c9c0e (patch)
tree3622243563c05a11f7656fea8b3d31f726195fb5 /models/migrations/v39.go
parent92123fe82a2dc4c01fdc180baaa7d2bfa2fe971a (diff)
downloadgitea-ebac051e7207181ac3d7bbe288536bf2224c9c0e.tar.gz
gitea-ebac051e7207181ac3d7bbe288536bf2224c9c0e.zip
Rewrite migrations to not depend on future code changes (#2604)
* v38 migration used an outdated version of RepoUnit model (#2602) * change repoUnit model in migration * fix v16 migration repo_unit table * fix lint error * move type definition inside function Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com> * fix lint error Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com> * Fix time tracking migration * Refactor code * Fix migration from Gogs * v38 migration used an outdated version of RepoUnit model (#2602) * change repoUnit model in migration * fix v16 migration repo_unit table * fix lint error * move type definition inside function Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com> * fix lint error Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com> * Fix time tracking migration * Refactor code * Fix migration from Gogs * add error check Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com> * Additiomal fixes for migrations * Fix timetracking migration * Add back nil check
Diffstat (limited to 'models/migrations/v39.go')
-rw-r--r--models/migrations/v39.go63
1 files changed, 36 insertions, 27 deletions
diff --git a/models/migrations/v39.go b/models/migrations/v39.go
index 41279484e1..95ae0c96a2 100644
--- a/models/migrations/v39.go
+++ b/models/migrations/v39.go
@@ -13,26 +13,37 @@ import (
"github.com/go-xorm/xorm"
)
-// Stopwatch see models/issue_stopwatch.go
-type Stopwatch struct {
- ID int64 `xorm:"pk autoincr"`
- IssueID int64 `xorm:"INDEX"`
- UserID int64 `xorm:"INDEX"`
- Created time.Time `xorm:"-"`
- CreatedUnix int64
-}
+func addTimetracking(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)"`
+ Index int
+ Config map[string]interface{} `xorm:"JSON"`
+ CreatedUnix int64 `xorm:"INDEX CREATED"`
+ Created time.Time `xorm:"-"`
+ }
-// TrackedTime see models/issue_tracked_time.go
-type TrackedTime struct {
- ID int64 `xorm:"pk autoincr" json:"id"`
- IssueID int64 `xorm:"INDEX" json:"issue_id"`
- UserID int64 `xorm:"INDEX" json:"user_id"`
- Created time.Time `xorm:"-" json:"created"`
- CreatedUnix int64 `json:"-"`
- Time int64 `json:"time"`
-}
+ // Stopwatch see models/issue_stopwatch.go
+ type Stopwatch struct {
+ ID int64 `xorm:"pk autoincr"`
+ IssueID int64 `xorm:"INDEX"`
+ UserID int64 `xorm:"INDEX"`
+ Created time.Time `xorm:"-"`
+ CreatedUnix int64
+ }
+
+ // TrackedTime see models/issue_tracked_time.go
+ type TrackedTime struct {
+ ID int64 `xorm:"pk autoincr" json:"id"`
+ IssueID int64 `xorm:"INDEX" json:"issue_id"`
+ UserID int64 `xorm:"INDEX" json:"user_id"`
+ Created time.Time `xorm:"-" json:"created"`
+ CreatedUnix int64 `json:"-"`
+ Time int64 `json:"time"`
+ }
-func addTimetracking(x *xorm.Engine) error {
if err := x.Sync2(new(Stopwatch)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
@@ -40,25 +51,23 @@ func addTimetracking(x *xorm.Engine) error {
return fmt.Errorf("Sync2: %v", err)
}
//Updating existing issue units
- var units []*RepoUnit
- x.Where("type = ?", V16UnitTypeIssues).Find(&units)
+ units := make([]*RepoUnit, 0, 100)
+ err := x.Where("`type` = ?", V16UnitTypeIssues).Find(&units)
+ if err != nil {
+ return fmt.Errorf("Query repo units: %v", err)
+ }
for _, unit := range units {
if unit.Config == nil {
unit.Config = make(map[string]interface{})
}
- changes := false
if _, ok := unit.Config["EnableTimetracker"]; !ok {
unit.Config["EnableTimetracker"] = setting.Service.DefaultEnableTimetracking
- changes = true
}
if _, ok := unit.Config["AllowOnlyContributorsToTrackTime"]; !ok {
unit.Config["AllowOnlyContributorsToTrackTime"] = setting.Service.DefaultAllowOnlyContributorsToTrackTime
- changes = true
}
- if changes {
- if _, err := x.ID(unit.ID).Cols("config").Update(unit); err != nil {
- return err
- }
+ if _, err := x.ID(unit.ID).Cols("config").Update(unit); err != nil {
+ return err
}
}
return nil