diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/migrations/migrations.go | 2 | ||||
-rw-r--r-- | models/migrations/v184.go | 47 | ||||
-rw-r--r-- | models/task.go | 8 |
3 files changed, 56 insertions, 1 deletions
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 8e4f30177b..880f55092d 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -317,6 +317,8 @@ var migrations = []Migration{ NewMigration("Add issue resource index table", addIssueResourceIndexTable), // v183 -> v184 NewMigration("Create PushMirror table", createPushMirrorTable), + // v184 -> v185 + NewMigration("Rename Task errors to message", renameTaskErrorsToMessage), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v184.go b/models/migrations/v184.go new file mode 100644 index 0000000000..b7be342b87 --- /dev/null +++ b/models/migrations/v184.go @@ -0,0 +1,47 @@ +// Copyright 2021 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" + + "code.gitea.io/gitea/modules/setting" + + "xorm.io/xorm" +) + +func renameTaskErrorsToMessage(x *xorm.Engine) error { + type Task struct { + Errors string `xorm:"TEXT"` // if task failed, saved the error reason + Type int + Status int `xorm:"index"` + } + + sess := x.NewSession() + defer sess.Close() + if err := sess.Begin(); err != nil { + return err + } + + if err := sess.Sync2(new(Task)); err != nil { + return fmt.Errorf("error on Sync2: %v", err) + } + + switch { + case setting.Database.UseMySQL: + if _, err := sess.Exec("ALTER TABLE `task` CHANGE errors message text"); err != nil { + return err + } + case setting.Database.UseMSSQL: + if _, err := sess.Exec("sp_rename 'task.errors', 'message', 'COLUMN'"); err != nil { + return err + } + default: + if _, err := sess.Exec("ALTER TABLE `task` RENAME COLUMN errors TO message"); err != nil { + return err + } + } + return sess.Commit() +} diff --git a/models/task.go b/models/task.go index 2743d91f66..5f9ccc6bfa 100644 --- a/models/task.go +++ b/models/task.go @@ -32,10 +32,16 @@ type Task struct { StartTime timeutil.TimeStamp EndTime timeutil.TimeStamp PayloadContent string `xorm:"TEXT"` - Errors string `xorm:"TEXT"` // if task failed, saved the error reason + Message string `xorm:"TEXT"` // if task failed, saved the error reason Created timeutil.TimeStamp `xorm:"created"` } +// TranslatableMessage represents JSON struct that can be translated with a Locale +type TranslatableMessage struct { + Format string + Args []interface{} `json:"omitempty"` +} + // LoadRepo loads repository of the task func (task *Task) LoadRepo() error { return task.loadRepo(x) |