Skip to content

Commit fed8e01

Browse files
lunnylafrikstechknowlogick
authored
Fix database keyword quote problem on migration v161 (#17522)
* support rerun migration v161 Co-authored-by: Lauris BH <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent e5b48dc commit fed8e01

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

models/migrations/v161.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package migrations
66

77
import (
8+
"context"
9+
810
"xorm.io/xorm"
911
)
1012

@@ -42,8 +44,17 @@ func convertTaskTypeToString(x *xorm.Engine) error {
4244
return err
4345
}
4446

47+
// to keep the migration could be rerun
48+
exist, err := x.Dialect().IsColumnExist(x.DB(), context.Background(), "hook_task", "type")
49+
if err != nil {
50+
return err
51+
}
52+
if !exist {
53+
return nil
54+
}
55+
4556
for i, s := range hookTaskTypes {
46-
if _, err := x.Exec("UPDATE hook_task set typ = ? where type=?", s, i); err != nil {
57+
if _, err := x.Exec("UPDATE hook_task set typ = ? where `type`=?", s, i); err != nil {
4758
return err
4859
}
4960
}

0 commit comments

Comments
 (0)