summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-12-02 21:17:24 +0800
committerGitHub <noreply@github.com>2021-12-02 21:17:24 +0800
commit4f98e82427ea6a12b223d4f798a7dafcd01b68c8 (patch)
tree349bb091e06c9396cafedd80d1e4752b4c1bf127 /models
parent34b5436ae1af2735546bb519a950eabf4990212d (diff)
downloadgitea-4f98e82427ea6a12b223d4f798a7dafcd01b68c8.tar.gz
gitea-4f98e82427ea6a12b223d4f798a7dafcd01b68c8.zip
Check if column exist before rename if exist, just return with no error (#17870)
* Check if column exist before rename if exist, just return with no error * Also check if errors column exist * Add comment for migration * Fix sqlite test
Diffstat (limited to 'models')
-rw-r--r--models/migrations/v184.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/models/migrations/v184.go b/models/migrations/v184.go
index b7be342b87..97bc72d5d9 100644
--- a/models/migrations/v184.go
+++ b/models/migrations/v184.go
@@ -5,6 +5,7 @@
package migrations
import (
+ "context"
"fmt"
"code.gitea.io/gitea/modules/setting"
@@ -19,6 +20,22 @@ func renameTaskErrorsToMessage(x *xorm.Engine) error {
Status int `xorm:"index"`
}
+ // This migration maybe rerun so that we should check if it has been run
+ messageExist, err := x.Dialect().IsColumnExist(x.DB(), context.Background(), "task", "message")
+ if err != nil {
+ return err
+ }
+
+ if messageExist {
+ errorsExist, err := x.Dialect().IsColumnExist(x.DB(), context.Background(), "task", "errors")
+ if err != nil {
+ return err
+ }
+ if !errorsExist {
+ return nil
+ }
+ }
+
sess := x.NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
@@ -29,6 +46,13 @@ func renameTaskErrorsToMessage(x *xorm.Engine) error {
return fmt.Errorf("error on Sync2: %v", err)
}
+ if messageExist {
+ // if both errors and message exist, drop message at first
+ if err := dropTableColumns(sess, "task", "message"); err != nil {
+ return err
+ }
+ }
+
switch {
case setting.Database.UseMySQL:
if _, err := sess.Exec("ALTER TABLE `task` CHANGE errors message text"); err != nil {