summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-06-16 23:02:24 +0100
committerGitHub <noreply@github.com>2021-06-16 18:02:24 -0400
commit6d69df28047bf7fd3e307391b484a93432615b90 (patch)
tree8a24ce0727f86625c4f469b6744f6f3f2fa27c86 /models
parent047c39e91bb39d4f31278d8c4082187894ea8263 (diff)
downloadgitea-6d69df28047bf7fd3e307391b484a93432615b90.tar.gz
gitea-6d69df28047bf7fd3e307391b484a93432615b90.zip
Add Status Updates whilst Gitea migrations are occurring (#15076)
* Add migrating message Signed-off-by: Andrew Thornton <art27@cantab.net> * simplify messenger Signed-off-by: Andrew Thornton <art27@cantab.net> * make messenger an interface Signed-off-by: Andrew Thornton <art27@cantab.net> * rename Signed-off-by: Andrew Thornton <art27@cantab.net> * prepare for merge Signed-off-by: Andrew Thornton <art27@cantab.net> * as per tech Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'models')
-rw-r--r--models/migrations/migrations.go2
-rw-r--r--models/migrations/v184.go47
-rw-r--r--models/task.go8
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)