2020-12-08 13:41:14 +03:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 21:20:29 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-08 13:41:14 +03:00
|
|
|
|
2022-11-02 11:54:36 +03:00
|
|
|
package v1_14 //nolint
|
2020-12-08 13:41:14 +03:00
|
|
|
|
|
|
|
import (
|
2021-11-05 01:47:01 +03:00
|
|
|
"context"
|
|
|
|
|
2022-11-02 11:54:36 +03:00
|
|
|
"code.gitea.io/gitea/models/migrations/base"
|
|
|
|
|
2020-12-08 13:41:14 +03:00
|
|
|
"xorm.io/xorm"
|
|
|
|
)
|
|
|
|
|
2022-11-02 11:54:36 +03:00
|
|
|
func ConvertTaskTypeToString(x *xorm.Engine) error {
|
2020-12-08 13:41:14 +03:00
|
|
|
const (
|
|
|
|
GOGS int = iota + 1
|
|
|
|
SLACK
|
|
|
|
GITEA
|
|
|
|
DISCORD
|
|
|
|
DINGTALK
|
|
|
|
TELEGRAM
|
|
|
|
MSTEAMS
|
|
|
|
FEISHU
|
|
|
|
MATRIX
|
2021-07-23 07:41:27 +03:00
|
|
|
WECHATWORK
|
2020-12-08 13:41:14 +03:00
|
|
|
)
|
|
|
|
|
2021-03-14 21:52:12 +03:00
|
|
|
hookTaskTypes := map[int]string{
|
2021-07-23 07:41:27 +03:00
|
|
|
GITEA: "gitea",
|
|
|
|
GOGS: "gogs",
|
|
|
|
SLACK: "slack",
|
|
|
|
DISCORD: "discord",
|
|
|
|
DINGTALK: "dingtalk",
|
|
|
|
TELEGRAM: "telegram",
|
|
|
|
MSTEAMS: "msteams",
|
|
|
|
FEISHU: "feishu",
|
|
|
|
MATRIX: "matrix",
|
|
|
|
WECHATWORK: "wechatwork",
|
2020-12-08 13:41:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type HookTask struct {
|
2021-01-06 18:11:23 +03:00
|
|
|
Typ string `xorm:"VARCHAR(16) index"`
|
2020-12-08 13:41:14 +03:00
|
|
|
}
|
2023-08-13 22:17:21 +03:00
|
|
|
if err := x.Sync(new(HookTask)); err != nil {
|
2020-12-08 13:41:14 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-11-05 01:47:01 +03:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2020-12-08 13:41:14 +03:00
|
|
|
for i, s := range hookTaskTypes {
|
2021-11-05 01:47:01 +03:00
|
|
|
if _, err := x.Exec("UPDATE hook_task set typ = ? where `type`=?", s, i); err != nil {
|
2020-12-08 13:41:14 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sess := x.NewSession()
|
|
|
|
defer sess.Close()
|
|
|
|
if err := sess.Begin(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-02 11:54:36 +03:00
|
|
|
if err := base.DropTableColumns(sess, "hook_task", "type"); err != nil {
|
2020-12-08 13:41:14 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sess.Commit()
|
|
|
|
}
|