From da475df36218d5dcf767af861d208320e7a1f6d2 Mon Sep 17 00:00:00 2001 From: LordofAvernus Date: Fri, 26 Jul 2024 11:43:14 +0000 Subject: [PATCH 1/2] feat: cannot created multiple tasks for one instance. --- sqle/api/controller/v1/instance_audit_plan.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sqle/api/controller/v1/instance_audit_plan.go b/sqle/api/controller/v1/instance_audit_plan.go index 4afa3e35a..446ee6db5 100644 --- a/sqle/api/controller/v1/instance_audit_plan.go +++ b/sqle/api/controller/v1/instance_audit_plan.go @@ -91,6 +91,14 @@ func CreateInstanceAuditPlan(c echo.Context) error { } instanceID = inst.ID instanceType = inst.DbType + // check instance audit plan exist + _, exist, err = model.GetStorage().GetInstanceAuditPlanByInstanceID(int64(inst.ID)) + if err != nil { + return controller.JSONBaseErrorReq(c, err) + } + if exist { + return controller.JSONBaseErrorReq(c, fmt.Errorf("current instance has audit plan")) + } // check operation user, err := controller.GetCurrentUser(c, dms.GetUser) if err != nil { @@ -103,6 +111,7 @@ func CreateInstanceAuditPlan(c echo.Context) error { if !canCreateAuditPlan { return controller.JSONBaseErrorReq(c, errors.NewUserNotPermissionError(model.GetOperationCodeDesc(uint(model.OP_AUDIT_PLAN_SAVE)))) } + } else { instanceType = req.InstanceType } From 6b7017fea64a2334c83e889cf28d5c2c3c76b659 Mon Sep 17 00:00:00 2001 From: LordofAvernus Date: Fri, 26 Jul 2024 11:43:52 +0000 Subject: [PATCH 2/2] fix: use real schema to show create table --- sqle/server/auditplan/task_type_mysql_schema_meta.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqle/server/auditplan/task_type_mysql_schema_meta.go b/sqle/server/auditplan/task_type_mysql_schema_meta.go index 915879618..783de83dc 100644 --- a/sqle/server/auditplan/task_type_mysql_schema_meta.go +++ b/sqle/server/auditplan/task_type_mysql_schema_meta.go @@ -84,7 +84,7 @@ func (at *BaseSchemaMetaTaskV2) extractSQL(logger *logrus.Entry, ap *AuditPlan, return nil, fmt.Errorf("use schema fail, error: %v", err) } for _, table := range tables { - sql, err := db.ShowCreateTable(utils.SupplementalQuotationMarks(ap.InstanceDatabase), utils.SupplementalQuotationMarks(table)) + sql, err := db.ShowCreateTable(utils.SupplementalQuotationMarks(schema), utils.SupplementalQuotationMarks(table)) if err != nil { return nil, fmt.Errorf("show create table fail, error: %v", err) }