提交 c490ab09 编写于 作者: N ning

fix: cli upgrade

上级 ac4ff33d
......@@ -18,9 +18,9 @@ func Upgrade(configFile string) error {
return err
}
ctx := ctx.NewContext(context.Background(), db, false)
ctx := ctx.NewContext(context.Background(), db, true)
for _, cluster := range config.Clusters {
count, err := models.GetDatasourcesCountBy(ctx, "", "", cluster.Name)
count, err := models.GetDatasourcesCountByName(ctx, cluster.Name)
if err != nil {
logger.Errorf("get datasource %s count error: %v", cluster.Name, err)
continue
......
......@@ -848,6 +848,10 @@ func AlertRuleUpgradeToV6(ctx *ctx.Context, dsm map[string]Datasource) error {
}
lst[i].DatasourceIds = string(b)
if lst[i].PromQl == "" {
continue
}
ruleConfig := PromRuleConfig{
Queries: []PromQuery{
{
......
......@@ -153,6 +153,15 @@ func GetDatasourceIdsByEngineName(ctx *ctx.Context, engineName string) ([]int64,
return ids, err
}
func GetDatasourcesCountByName(ctx *ctx.Context, name string) (int64, error) {
session := DB(ctx).Model(&Datasource{})
if name != "" {
session = session.Where("name = ?", name)
}
return Count(session)
}
func GetDatasourcesCountBy(ctx *ctx.Context, typ, cate, name string) (int64, error) {
session := DB(ctx).Model(&Datasource{})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册