From 251fdaaf41034a41ce839871081b4ec353287732 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 3 Nov 2021 12:33:38 +0800 Subject: [PATCH] Fix database keyword quote problem on migration v161 (#17523) * support rerun migration v161 --- 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 4ca9f01218..283c44464c 100644 --- a/models/migrations/v161.go +++ b/models/migrations/v161.go @@ -5,6 +5,8 @@ package migrations import ( + "context" + "xorm.io/xorm" ) @@ -40,8 +42,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 } }