summaryrefslogtreecommitdiffstats
path: root/models/migrations/v49.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-12-13 16:52:18 +0200
committerGitHub <noreply@github.com>2017-12-13 16:52:18 +0200
commitc06cc740dea46f3aff58e0eded4208232bb5902d (patch)
tree8f17cf90828fb06133a14cdee2df67ea6db75550 /models/migrations/v49.go
parentd3c5911ffce8758d020b301e667869aa2e80ce6a (diff)
downloadgitea-c06cc740dea46f3aff58e0eded4208232bb5902d.tar.gz
gitea-c06cc740dea46f3aff58e0eded4208232bb5902d.zip
Reorder migrations, skip errors if running migration again (#3160)
* Reorder migrations, skip errors if running migration again * Rename migration file names to match migration version * Add note about ingored error
Diffstat (limited to 'models/migrations/v49.go')
-rw-r--r--models/migrations/v49.go64
1 files changed, 53 insertions, 11 deletions
diff --git a/models/migrations/v49.go b/models/migrations/v49.go
index ab57d27de0..9e98de5cf2 100644
--- a/models/migrations/v49.go
+++ b/models/migrations/v49.go
@@ -8,24 +8,66 @@ import (
"fmt"
"time"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/setting"
"github.com/go-xorm/xorm"
)
-func addLFSLock(x *xorm.Engine) error {
- // LFSLock see models/lfs_lock.go
- type LFSLock struct {
- ID int64 `xorm:"pk autoincr"`
- RepoID int64 `xorm:"INDEX NOT NULL"`
- Owner *models.User `xorm:"-"`
- OwnerID int64 `xorm:"INDEX NOT NULL"`
- Path string `xorm:"TEXT"`
- Created time.Time `xorm:"created"`
+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)"`
+ Config map[string]interface{} `xorm:"JSON"`
+ CreatedUnix int64 `xorm:"INDEX CREATED"`
+ Created time.Time `xorm:"-"`
}
- if err := x.Sync2(new(LFSLock)); err != nil {
+ // 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"`
+ }
+
+ if err := x.Sync2(new(Stopwatch)); err != nil {
return fmt.Errorf("Sync2: %v", err)
}
+ if err := x.Sync2(new(TrackedTime)); err != nil {
+ return fmt.Errorf("Sync2: %v", err)
+ }
+ //Updating existing issue 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{})
+ }
+ if _, ok := unit.Config["EnableTimetracker"]; !ok {
+ unit.Config["EnableTimetracker"] = setting.Service.DefaultEnableTimetracking
+ }
+ if _, ok := unit.Config["AllowOnlyContributorsToTrackTime"]; !ok {
+ unit.Config["AllowOnlyContributorsToTrackTime"] = setting.Service.DefaultAllowOnlyContributorsToTrackTime
+ }
+ if _, err := x.ID(unit.ID).Cols("config").Update(unit); err != nil {
+ return err
+ }
+ }
return nil
}