From fed8e01ca118b75430bed48d4424a9b83879c5b1 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 5 Nov 2021 06:47:01 +0800 Subject: [PATCH] Fix database keyword quote problem on migration v161 (#17522) * support rerun migration v161 Co-authored-by: Lauris BH Co-authored-by: techknowlogick --- models/migrations/v161.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/models/migrations/v161.go b/models/migrations/v161.go index 7ef06b4c26..af6bdf16aa 100644 --- a/models/migrations/v161.go +++ b/models/migrations/v161.go @@ -5,6 +5,8 @@ package migrations import ( + "context" + "xorm.io/xorm" ) @@ -42,8 +44,17 @@ func convertTaskTypeToString(x *xorm.Engine) error { return err } + // to keep the migration could be rerun + exist, err := x.Dialect().IsColumnExist(x.DB(), context.Background(), "hook_task", "type") + if err != nil { + return err + } + if !exist { + return nil + } + for i, s := range hookTaskTypes { - if _, err := x.Exec("UPDATE hook_task set typ = ? where type=?", s, i); err != nil { + if _, err := x.Exec("UPDATE hook_task set typ = ? where `type`=?", s, i); err != nil { return err } }