From 495632a0645f65bde5f20f7dbb3be3b404a8ddb8 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Wed, 1 Jun 2022 12:58:09 +0800 Subject: [PATCH 1/2] fix alert rule delete by service --- src/models/alert_rule.go | 8 ++++++-- src/webapi/router/router.go | 2 +- src/webapi/router/router_alert_rule.go | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/models/alert_rule.go b/src/models/alert_rule.go index 5719da5c..cebe8ca3 100644 --- a/src/models/alert_rule.go +++ b/src/models/alert_rule.go @@ -237,9 +237,13 @@ func (ar *AlertRule) DB2FE() { json.Unmarshal([]byte(ar.AlgoParams), &ar.AlgoParamsJson) } -func AlertRuleDels(ids []int64, busiGroupId int64) error { +func AlertRuleDels(ids []int64, bgid ...int64) error { for i := 0; i < len(ids); i++ { - ret := DB().Where("id = ? and group_id=?", ids[i], busiGroupId).Delete(&AlertRule{}) + session := DB().Where("id = ?", ids[i]) + if len(bgid) > 0 { + session = session.Where("group_id = ?", bgid[0]) + } + ret := session.Delete(&AlertRule{}) if ret.Error != nil { return ret.Error } diff --git a/src/webapi/router/router.go b/src/webapi/router/router.go index 3f13e3e9..b3e33fce 100644 --- a/src/webapi/router/router.go +++ b/src/webapi/router/router.go @@ -278,7 +278,7 @@ func configRoute(r *gin.Engine, version string) { service.GET("/alert-rules", alertRuleGets) service.POST("/alert-rules", alertRuleAddByService) - service.DELETE("/alert-rules", alertRuleDel) + service.DELETE("/alert-rules", alertRuleDelByService) service.PUT("/alert-rule/:arid", alertRulePutByService) service.GET("/alert-rule/:arid", alertRuleGet) service.GET("/alert-rules-get-by-prod", alertRulesGetByProds) diff --git a/src/webapi/router/router_alert_rule.go b/src/webapi/router/router_alert_rule.go index 7bd2fe30..2d1272de 100644 --- a/src/webapi/router/router_alert_rule.go +++ b/src/webapi/router/router_alert_rule.go @@ -129,6 +129,13 @@ func alertRuleDel(c *gin.Context) { ginx.NewRender(c).Message(models.AlertRuleDels(f.Ids, ginx.UrlParamInt64(c, "id"))) } +func alertRuleDelByService(c *gin.Context) { + var f idsForm + ginx.BindJSON(c, &f) + f.Verify() + ginx.NewRender(c).Message(models.AlertRuleDels(f.Ids)) +} + func alertRulePutByFE(c *gin.Context) { var f models.AlertRule ginx.BindJSON(c, &f) From a4ef5fca4618b40d626c70349813d723e3c77bb1 Mon Sep 17 00:00:00 2001 From: xtan <38320121+tanxiao1990@users.noreply.github.com> Date: Wed, 1 Jun 2022 19:57:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?pg=E6=95=B0=E6=8D=AE=E5=BA=93=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E8=84=9A=E6=9C=AC=E5=AD=97=E6=AE=B5=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=20(#969)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: tanxiao --- docker/initsql_for_postgres/a-n9e-for-Postgres.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/initsql_for_postgres/a-n9e-for-Postgres.sql b/docker/initsql_for_postgres/a-n9e-for-Postgres.sql index bda54179..30b78d67 100644 --- a/docker/initsql_for_postgres/a-n9e-for-Postgres.sql +++ b/docker/initsql_for_postgres/a-n9e-for-Postgres.sql @@ -9,6 +9,7 @@ CREATE TABLE users ( portrait varchar(255) not null default '' , roles varchar(255) not null , contacts varchar(1024) , + maintainer smallint not null default 0, create_at bigint not null default 0, create_by varchar(64) not null default '', update_at bigint not null default 0,