diff --git a/sqle/api/controller/v1/backup.go b/sqle/api/controller/v1/backup.go new file mode 100644 index 000000000..e5ebe2436 --- /dev/null +++ b/sqle/api/controller/v1/backup.go @@ -0,0 +1,92 @@ +package v1 + +import "github.com/labstack/echo/v4" + +type UpdateSqlBackupStrategyReq struct { + Strategy string `json:"strategy" enum:"none,manual,reverse_sql,origin_row"` +} + +// UpdateSqlBackupStrategy +// @Summary 更新单条SQL的备份策略 +// @Description update back up strategy for one sql in workflow +// @Tags workflow +// @Accept json +// @Produce json +// @Id UpdateSqlBackupStrategyV1 +// @Security ApiKeyAuth +// @Param task_id path string true "task id" +// @Param sql_id path string true "sql id" +// @Param strategy body v1.UpdateSqlBackupStrategyReq true "update back up strategy for one sql in workflow" +// @Success 200 {object} controller.BaseRes +// @router /v1/tasks/audits/{task_id}/sqls/{sql_id}/ [patch] +func UpdateSqlBackupStrategy(c echo.Context) error { + return nil +} + +type UpdateTaskBackupStrategyReq struct { + Strategy string `json:"strategy" enum:"none,manual,reverse_sql,origin_row"` +} + +// UpdateTaskBackupStrategy +// @Summary 更新工单中数据源对应所有SQL的备份策略 +// @Description update back up strategy for all sqls in task +// @Tags workflow +// @Accept json +// @Produce json +// @Id UpdateTaskBackupStrategyV1 +// @Security ApiKeyAuth +// @Param task_id path string true "task id" +// @Param strategy body v1.UpdateTaskBackupStrategyReq true "update back up strategy for sqls in workflow" +// @Success 200 {object} controller.BaseRes +// @router /v1/tasks/audits/{task_id}/ [patch] +func UpdateTaskBackupStrategy(c echo.Context) error { + return nil +} + +// @Summary 下载工单中的SQL备份 +// @Description download SQL back up file for the audit task +// @Tags task +// @Id downloadBackupFileV1 +// @Security ApiKeyAuth +// @Param workflow_id path string true "workflow id" +// @Param project_name path string true "project name" +// @Param task_id path string true "task id" +// @Success 200 file 1 "sql file" +// @router /v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/backup_files/download [get] +func DownloadSqlBackupFile(c echo.Context) error { + return nil +} + +type BackupSqlListReq struct { + FilterInstanceId string `json:"filter_instance_id" query:"filter_instance_id"` + FilterExecStatus string `json:"filter_exec_status" query:"filter_exec_status"` + PageIndex uint32 `json:"page_index" query:"page_index" valid:"required"` + PageSize uint32 `json:"page_size" query:"page_size" valid:"required"` +} + +type BackupSqlListRes struct { + ExecOrder uint `json:"exec_order"` + ExecSqlID uint `json:"exec_sql_id"` + OriginSQL string `json:"origin_sql"` + BackupSqls []string `json:"backup_sqls"` + BackupStrategy string `json:"backup_strategy" enum:"none,manual,reverse_sql,origin_row"` + InstanceName string `json:"instance_name"` + InstanceId string `json:"instance_id "` + ExecStatus string `json:"exec_status"` + Description string `json:"description"` +} + +// @Summary 获取工单下所有回滚SQL的列表 +// @Description get backup sql list +// @Tags workflow +// @Id GetBackupSqlListV1 +// @Security ApiKeyAuth +// @Param filter_exec_status query string false "filter: exec status of task sql" Enums(initialized,doing,succeeded,failed,manually_executed,terminating,terminate_succeeded,terminate_failed) +// @Param filter_instance_id query uint false "filter: instance id in workflow" +// @Param page_index query string true "page index" +// @Param page_size query string true "page size" +// @Success 200 {object} v1.BackupSqlListRes +// @router /v1/projects/{project_name}/workflows/{workflow_id}/backup_sqls [get] +func GetBackupSqlList(c echo.Context) error { + return nil +} diff --git a/sqle/api/controller/v1/task.go b/sqle/api/controller/v1/task.go index aa7ef9f77..451b7e518 100644 --- a/sqle/api/controller/v1/task.go +++ b/sqle/api/controller/v1/task.go @@ -40,6 +40,7 @@ type CreateAuditTaskReqV1 struct { InstanceSchema string `json:"instance_schema" form:"instance_schema" example:"db1"` Sql string `json:"sql" form:"sql" example:"alter table tb1 drop columns c1"` ExecMode string `json:"exec_mode" form:"exec_mode" enums:"sql_file,sqls"` + EnableBackup bool `json:"enable_backup" form:"enable_backup"` FileOrderMethod string `json:"file_order_method" form:"file_order_method"` } @@ -49,20 +50,22 @@ type GetAuditTaskResV1 struct { } type AuditTaskResV1 struct { - Id uint `json:"task_id"` - InstanceName string `json:"instance_name"` - InstanceDbType string `json:"instance_db_type"` - InstanceSchema string `json:"instance_schema" example:"db1"` - AuditLevel string `json:"audit_level" enums:"normal,notice,warn,error,"` - Score int32 `json:"score"` - PassRate float64 `json:"pass_rate"` - Status string `json:"status" enums:"initialized,audited,executing,exec_success,exec_failed,manually_executed"` - SQLSource string `json:"sql_source" enums:"form_data,sql_file,mybatis_xml_file,audit_plan,zip_file,git_repository"` - ExecStartTime *time.Time `json:"exec_start_time,omitempty"` - ExecEndTime *time.Time `json:"exec_end_time,omitempty"` - FileOrderMethod string `json:"file_order_method,omitempty"` - ExecMode string `json:"exec_mode,omitempty"` - AuditFiles []AuditFileResp `json:"audit_files,omitempty"` + Id uint `json:"task_id"` + InstanceName string `json:"instance_name"` + InstanceDbType string `json:"instance_db_type"` + InstanceSchema string `json:"instance_schema" example:"db1"` + AuditLevel string `json:"audit_level" enums:"normal,notice,warn,error,"` + Score int32 `json:"score"` + PassRate float64 `json:"pass_rate"` + Status string `json:"status" enums:"initialized,audited,executing,exec_success,exec_failed,manually_executed"` + SQLSource string `json:"sql_source" enums:"form_data,sql_file,mybatis_xml_file,audit_plan,zip_file,git_repository"` + ExecStartTime *time.Time `json:"exec_start_time,omitempty"` + ExecEndTime *time.Time `json:"exec_end_time,omitempty"` + FileOrderMethod string `json:"file_order_method,omitempty"` + ExecMode string `json:"exec_mode,omitempty"` + EnableBackup bool `json:"enable_backup"` + BackupConflictWithInstance bool `json:"backup_conflict_with_instance"` + AuditFiles []AuditFileResp `json:"audit_files,omitempty"` } type AuditFileResp struct { @@ -285,6 +288,7 @@ func getFileHeaderFromContext(c echo.Context) (fileHeader *multipart.FileHeader, // @Param project_name path string true "project name" // @Param instance_name formData string true "instance name" // @Param instance_schema formData string false "schema of instance" +// @Param enable_backup formData bool false "enable backup" // @Param sql formData string false "sqls for audit" // @Param input_sql_file formData file false "input SQL file" // @Param input_mybatis_xml_file formData file false "input mybatis XML file" @@ -295,6 +299,7 @@ func getFileHeaderFromContext(c echo.Context) (fileHeader *multipart.FileHeader, // @Success 200 {object} v1.GetAuditTaskResV1 // @router /v1/projects/{project_name}/tasks/audits [post] func CreateAndAuditTask(c echo.Context) error { + // TODO 不同SQL模式审核增加备份配置 req := new(CreateAuditTaskReqV1) if err := controller.BindAndValidateReq(c, req); err != nil { return err @@ -926,8 +931,9 @@ func CreateAuditTasksGroupV1(c echo.Context) error { } type AuditTaskGroupReqV1 struct { - TaskGroupId uint `json:"task_group_id" form:"task_group_id" valid:"required"` - Sql string `json:"sql" form:"sql" example:"alter table tb1 drop columns c1"` + TaskGroupId uint `json:"task_group_id" form:"task_group_id" valid:"required"` + Sql string `json:"sql" form:"sql" example:"alter table tb1 drop columns c1"` + EnableBackup bool `json:"enable_backup" form:"enable_backup"` } type AuditTaskGroupRes struct { @@ -954,13 +960,15 @@ type AuditTaskGroupResV1 struct { // @Security ApiKeyAuth // @Param task_group_id formData uint true "group id of tasks" // @Param sql formData string false "sqls for audit" +// @Param enable_backup formData bool false "enable backup" // @Param file_order_method formData string false "file order method" // @Param input_sql_file formData file false "input SQL file" // @Param input_mybatis_xml_file formData file false "input mybatis XML file" // @Param input_zip_file formData file false "input ZIP file" // @Success 200 {object} v1.AuditTaskGroupResV1 // @router /v1/task_groups/audit [post] -func AuditTaskGroupV1(c echo.Context) error { +func AuditTaskGroupV1(c echo.Context) error { + // TODO 单数据源审核,以及多数据源相同SQL模式审核,增加备份配置 req := new(AuditTaskGroupReqV1) if err := controller.BindAndValidateReq(c, req); err != nil { return err diff --git a/sqle/api/controller/v2/task.go b/sqle/api/controller/v2/task.go index f1f8d13f0..8de22759b 100644 --- a/sqle/api/controller/v2/task.go +++ b/sqle/api/controller/v2/task.go @@ -28,18 +28,21 @@ type GetAuditTaskSQLsResV2 struct { } type AuditTaskSQLResV2 struct { - Number uint `json:"number"` - ExecSQL string `json:"exec_sql"` - SQLSourceFile string `json:"sql_source_file"` - SQLStartLine uint64 `json:"sql_start_line"` - AuditResult []*AuditResult `json:"audit_result"` - AuditLevel string `json:"audit_level"` - AuditStatus string `json:"audit_status"` - ExecResult string `json:"exec_result"` - ExecStatus string `json:"exec_status"` - RollbackSQL string `json:"rollback_sql,omitempty"` - Description string `json:"description"` - SQLType string `json:"sql_type"` + ExecSqlID uint `json:"exec_sql_id"` + Number uint `json:"number"` + ExecSQL string `json:"exec_sql"` + SQLSourceFile string `json:"sql_source_file"` + SQLStartLine uint64 `json:"sql_start_line"` + AuditResult []*AuditResult `json:"audit_result"` + AuditLevel string `json:"audit_level"` + AuditStatus string `json:"audit_status"` + ExecResult string `json:"exec_result"` + ExecStatus string `json:"exec_status"` + RollbackSQL string `json:"rollback_sql,omitempty"` + Description string `json:"description"` + SQLType string `json:"sql_type"` + BackupStrategy string `json:"backup_strategy" enum:"none,manual,reverse_sql,origin_row"` + BackupStrategyTip string `json:"backup_strategy_tip"` } type AuditResult struct { diff --git a/sqle/api/controller/v2/workflow.go b/sqle/api/controller/v2/workflow.go index 0a2b52dbe..b897cef87 100644 --- a/sqle/api/controller/v2/workflow.go +++ b/sqle/api/controller/v2/workflow.go @@ -583,10 +583,11 @@ func convertWorkflowToTasksSummaryRes(taskDetails []*model.WorkflowTasksSummaryD } type CreateWorkflowReqV2 struct { - Subject string `json:"workflow_subject" form:"workflow_subject" valid:"required,name"` - Desc string `json:"desc" form:"desc"` - SqlVersionID *uint `json:"sql_version_id" form:"sql_version_id"` - TaskIds []uint `json:"task_ids" form:"task_ids" valid:"required"` + Subject string `json:"workflow_subject" form:"workflow_subject" valid:"required,name"` + Desc string `json:"desc" form:"desc"` + SqlVersionID *uint `json:"sql_version_id" form:"sql_version_id"` + TaskIds []uint `json:"task_ids" form:"task_ids" valid:"required"` + AssociatedWorkflowId string `json:"associated_workflow_id"` } type CreateWorkflowResV2 struct { @@ -794,7 +795,7 @@ type UpdateWorkflowReqV2 struct { } // UpdateWorkflowV2 -// @Summary 更新工单(驳回后才可更新) +// @Summary 更新工单(工单被驳回、工单被关闭、执行成功、执行失败后才可更新) // @Description update workflow when it is rejected to creator. // @Tags workflow // @Accept json @@ -901,6 +902,7 @@ func UpdateWorkflowV2(c echo.Context) error { return controller.JSONBaseErrorReq(c, errTaskHasBeenUsed) } // When workflow status is rejected or exec failed, the user can recommit workflow. And the workflow becomes waiting for the audit process. + // TODO 重试工单 驳回、成功、失败、关闭的工单可以重试,应抽离出一个函数 if workflow.Record.Status != model.WorkflowStatusReject && workflow.Record.Status != model.WorkflowStatusExecFailed { return controller.JSONBaseErrorReq(c, errors.New(errors.DataInvalid, fmt.Errorf("workflow status is %s, not allow operate it", workflow.Record.Status))) diff --git a/sqle/docs/docs.go b/sqle/docs/docs.go index e9af729cf..b4859d7e2 100644 --- a/sqle/docs/docs.go +++ b/sqle/docs/docs.go @@ -6606,6 +6606,12 @@ var doc = `{ "name": "instance_schema", "in": "formData" }, + { + "type": "boolean", + "description": "enable backup", + "name": "enable_backup", + "in": "formData" + }, { "type": "string", "description": "sqls for audit", @@ -7109,6 +7115,67 @@ var doc = `{ } } }, + "/v1/projects/{project_name}/workflows/{workflow_id}/backup_sqls": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get backup sql list", + "tags": [ + "workflow" + ], + "summary": "获取工单下所有回滚SQL的列表", + "operationId": "GetBackupSqlListV1", + "parameters": [ + { + "enum": [ + "initialized", + "doing", + "succeeded", + "failed", + "manually_executed", + "terminating", + "terminate_succeeded", + "terminate_failed" + ], + "type": "string", + "description": "filter: exec status of task sql", + "name": "filter_exec_status", + "in": "query" + }, + { + "type": "integer", + "description": "filter: instance id in workflow", + "name": "filter_instance_id", + "in": "query" + }, + { + "type": "string", + "description": "page index", + "name": "page_index", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "page size", + "name": "page_size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.BackupSqlListRes" + } + } + } + } + }, "/v1/projects/{project_name}/workflows/{workflow_id}/tasks/terminate": { "post": { "security": [ @@ -7194,6 +7261,52 @@ var doc = `{ } } }, + "/v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/backup_files/download": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "download SQL back up file for the audit task", + "tags": [ + "task" + ], + "summary": "下载工单中的SQL备份", + "operationId": "downloadBackupFileV1", + "parameters": [ + { + "type": "string", + "description": "workflow id", + "name": "workflow_id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "task id", + "name": "task_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "sql file", + "schema": { + "type": "file" + } + } + } + } + }, "/v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/order_file": { "post": { "security": [ @@ -8865,6 +8978,12 @@ var doc = `{ "name": "sql", "in": "formData" }, + { + "type": "boolean", + "description": "enable backup", + "name": "enable_backup", + "in": "formData" + }, { "type": "string", "description": "file order method", @@ -8930,6 +9049,51 @@ var doc = `{ } } } + }, + "patch": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update back up strategy for all sqls in task", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "workflow" + ], + "summary": "更新工单中数据源对应所有SQL的备份策略", + "operationId": "UpdateTaskBackupStrategyV1", + "parameters": [ + { + "type": "string", + "description": "task id", + "name": "task_id", + "in": "path", + "required": true + }, + { + "description": "update back up strategy for sqls in workflow", + "name": "strategy", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.UpdateTaskBackupStrategyReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controller.BaseRes" + } + } + } } }, "/v1/tasks/audits/{task_id}/origin_file": { @@ -9244,6 +9408,60 @@ var doc = `{ } } }, + "/v1/tasks/audits/{task_id}/sqls/{sql_id}/": { + "patch": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update back up strategy for one sql in workflow", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "workflow" + ], + "summary": "更新单条SQL的备份策略", + "operationId": "UpdateSqlBackupStrategyV1", + "parameters": [ + { + "type": "string", + "description": "task id", + "name": "task_id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "sql id", + "name": "sql_id", + "in": "path", + "required": true + }, + { + "description": "update back up strategy for one sql in workflow", + "name": "strategy", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.UpdateSqlBackupStrategyReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controller.BaseRes" + } + } + } + } + }, "/v1/tasks/file_order_methods": { "get": { "security": [ @@ -10115,7 +10333,7 @@ var doc = `{ "tags": [ "workflow" ], - "summary": "更新工单(驳回后才可更新)", + "summary": "更新工单(工单被驳回、工单被关闭、执行成功、执行失败后才可更新)", "operationId": "updateWorkflowV2", "parameters": [ { @@ -11341,6 +11559,12 @@ var doc = `{ "" ] }, + "backup_conflict_with_instance": { + "type": "boolean" + }, + "enable_backup": { + "type": "boolean" + }, "exec_end_time": { "type": "string" }, @@ -11479,6 +11703,41 @@ var doc = `{ } } }, + "v1.BackupSqlListRes": { + "type": "object", + "properties": { + "backup_sqls": { + "type": "array", + "items": { + "type": "string" + } + }, + "backup_strategy": { + "type": "string" + }, + "description": { + "type": "string" + }, + "exec_order": { + "type": "integer" + }, + "exec_sql_id": { + "type": "integer" + }, + "exec_status": { + "type": "string" + }, + "instance_id ": { + "type": "string" + }, + "instance_name": { + "type": "string" + }, + "origin_sql": { + "type": "string" + } + } + }, "v1.BatchAssociateWorkflowsWithVersionReqV1": { "type": "object", "properties": { @@ -11749,6 +12008,9 @@ var doc = `{ "v1.CreateAuditTaskReqV1": { "type": "object", "properties": { + "enable_backup": { + "type": "boolean" + }, "exec_mode": { "type": "string", "enum": [ @@ -17157,6 +17419,14 @@ var doc = `{ } } }, + "v1.UpdateSqlBackupStrategyReq": { + "type": "object", + "properties": { + "strategy": { + "type": "string" + } + } + }, "v1.UpdateSqlFileOrderV1Req": { "type": "object", "properties": { @@ -17232,6 +17502,14 @@ var doc = `{ } } }, + "v1.UpdateTaskBackupStrategyReq": { + "type": "object", + "properties": { + "strategy": { + "type": "string" + } + } + }, "v1.UpdateWechatConfigurationReqV1": { "type": "object", "required": [ @@ -18330,6 +18608,12 @@ var doc = `{ "audit_status": { "type": "string" }, + "backup_strategy": { + "type": "string" + }, + "backup_strategy_tip": { + "type": "string" + }, "description": { "type": "string" }, @@ -18339,6 +18623,9 @@ var doc = `{ "exec_sql": { "type": "string" }, + "exec_sql_id": { + "type": "integer" + }, "exec_status": { "type": "string" }, @@ -18384,6 +18671,9 @@ var doc = `{ "v2.CreateWorkflowReqV2": { "type": "object", "properties": { + "associated_workflow_id": { + "type": "string" + }, "desc": { "type": "string" }, diff --git a/sqle/docs/swagger.json b/sqle/docs/swagger.json index fd0cce2d4..de56b6136 100644 --- a/sqle/docs/swagger.json +++ b/sqle/docs/swagger.json @@ -6590,6 +6590,12 @@ "name": "instance_schema", "in": "formData" }, + { + "type": "boolean", + "description": "enable backup", + "name": "enable_backup", + "in": "formData" + }, { "type": "string", "description": "sqls for audit", @@ -7093,6 +7099,67 @@ } } }, + "/v1/projects/{project_name}/workflows/{workflow_id}/backup_sqls": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "get backup sql list", + "tags": [ + "workflow" + ], + "summary": "获取工单下所有回滚SQL的列表", + "operationId": "GetBackupSqlListV1", + "parameters": [ + { + "enum": [ + "initialized", + "doing", + "succeeded", + "failed", + "manually_executed", + "terminating", + "terminate_succeeded", + "terminate_failed" + ], + "type": "string", + "description": "filter: exec status of task sql", + "name": "filter_exec_status", + "in": "query" + }, + { + "type": "integer", + "description": "filter: instance id in workflow", + "name": "filter_instance_id", + "in": "query" + }, + { + "type": "string", + "description": "page index", + "name": "page_index", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "page size", + "name": "page_size", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/v1.BackupSqlListRes" + } + } + } + } + }, "/v1/projects/{project_name}/workflows/{workflow_id}/tasks/terminate": { "post": { "security": [ @@ -7178,6 +7245,52 @@ } } }, + "/v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/backup_files/download": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "download SQL back up file for the audit task", + "tags": [ + "task" + ], + "summary": "下载工单中的SQL备份", + "operationId": "downloadBackupFileV1", + "parameters": [ + { + "type": "string", + "description": "workflow id", + "name": "workflow_id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "project name", + "name": "project_name", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "task id", + "name": "task_id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "sql file", + "schema": { + "type": "file" + } + } + } + } + }, "/v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/order_file": { "post": { "security": [ @@ -8849,6 +8962,12 @@ "name": "sql", "in": "formData" }, + { + "type": "boolean", + "description": "enable backup", + "name": "enable_backup", + "in": "formData" + }, { "type": "string", "description": "file order method", @@ -8914,6 +9033,51 @@ } } } + }, + "patch": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update back up strategy for all sqls in task", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "workflow" + ], + "summary": "更新工单中数据源对应所有SQL的备份策略", + "operationId": "UpdateTaskBackupStrategyV1", + "parameters": [ + { + "type": "string", + "description": "task id", + "name": "task_id", + "in": "path", + "required": true + }, + { + "description": "update back up strategy for sqls in workflow", + "name": "strategy", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.UpdateTaskBackupStrategyReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controller.BaseRes" + } + } + } } }, "/v1/tasks/audits/{task_id}/origin_file": { @@ -9228,6 +9392,60 @@ } } }, + "/v1/tasks/audits/{task_id}/sqls/{sql_id}/": { + "patch": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "update back up strategy for one sql in workflow", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "workflow" + ], + "summary": "更新单条SQL的备份策略", + "operationId": "UpdateSqlBackupStrategyV1", + "parameters": [ + { + "type": "string", + "description": "task id", + "name": "task_id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "sql id", + "name": "sql_id", + "in": "path", + "required": true + }, + { + "description": "update back up strategy for one sql in workflow", + "name": "strategy", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/v1.UpdateSqlBackupStrategyReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/controller.BaseRes" + } + } + } + } + }, "/v1/tasks/file_order_methods": { "get": { "security": [ @@ -10099,7 +10317,7 @@ "tags": [ "workflow" ], - "summary": "更新工单(驳回后才可更新)", + "summary": "更新工单(工单被驳回、工单被关闭、执行成功、执行失败后才可更新)", "operationId": "updateWorkflowV2", "parameters": [ { @@ -11325,6 +11543,12 @@ "" ] }, + "backup_conflict_with_instance": { + "type": "boolean" + }, + "enable_backup": { + "type": "boolean" + }, "exec_end_time": { "type": "string" }, @@ -11463,6 +11687,41 @@ } } }, + "v1.BackupSqlListRes": { + "type": "object", + "properties": { + "backup_sqls": { + "type": "array", + "items": { + "type": "string" + } + }, + "backup_strategy": { + "type": "string" + }, + "description": { + "type": "string" + }, + "exec_order": { + "type": "integer" + }, + "exec_sql_id": { + "type": "integer" + }, + "exec_status": { + "type": "string" + }, + "instance_id ": { + "type": "string" + }, + "instance_name": { + "type": "string" + }, + "origin_sql": { + "type": "string" + } + } + }, "v1.BatchAssociateWorkflowsWithVersionReqV1": { "type": "object", "properties": { @@ -11733,6 +11992,9 @@ "v1.CreateAuditTaskReqV1": { "type": "object", "properties": { + "enable_backup": { + "type": "boolean" + }, "exec_mode": { "type": "string", "enum": [ @@ -17141,6 +17403,14 @@ } } }, + "v1.UpdateSqlBackupStrategyReq": { + "type": "object", + "properties": { + "strategy": { + "type": "string" + } + } + }, "v1.UpdateSqlFileOrderV1Req": { "type": "object", "properties": { @@ -17216,6 +17486,14 @@ } } }, + "v1.UpdateTaskBackupStrategyReq": { + "type": "object", + "properties": { + "strategy": { + "type": "string" + } + } + }, "v1.UpdateWechatConfigurationReqV1": { "type": "object", "required": [ @@ -18314,6 +18592,12 @@ "audit_status": { "type": "string" }, + "backup_strategy": { + "type": "string" + }, + "backup_strategy_tip": { + "type": "string" + }, "description": { "type": "string" }, @@ -18323,6 +18607,9 @@ "exec_sql": { "type": "string" }, + "exec_sql_id": { + "type": "integer" + }, "exec_status": { "type": "string" }, @@ -18368,6 +18655,9 @@ "v2.CreateWorkflowReqV2": { "type": "object", "properties": { + "associated_workflow_id": { + "type": "string" + }, "desc": { "type": "string" }, diff --git a/sqle/docs/swagger.yaml b/sqle/docs/swagger.yaml index 0437c540e..277ce7dec 100644 --- a/sqle/docs/swagger.yaml +++ b/sqle/docs/swagger.yaml @@ -388,6 +388,10 @@ definitions: - error - "" type: string + backup_conflict_with_instance: + type: boolean + enable_backup: + type: boolean exec_end_time: type: string exec_mode: @@ -482,6 +486,29 @@ definitions: total_sql_count: type: integer type: object + v1.BackupSqlListRes: + properties: + backup_sqls: + items: + type: string + type: array + backup_strategy: + type: string + description: + type: string + exec_order: + type: integer + exec_sql_id: + type: integer + exec_status: + type: string + 'instance_id ': + type: string + instance_name: + type: string + origin_sql: + type: string + type: object v1.BatchAssociateWorkflowsWithVersionReqV1: properties: workflow_ids: @@ -664,6 +691,8 @@ definitions: type: object v1.CreateAuditTaskReqV1: properties: + enable_backup: + type: boolean exec_mode: enum: - sql_file @@ -4356,6 +4385,11 @@ definitions: type: string type: array type: object + v1.UpdateSqlBackupStrategyReq: + properties: + strategy: + type: string + type: object v1.UpdateSqlFileOrderV1Req: properties: files_to_sort: @@ -4406,6 +4440,11 @@ definitions: example: http://10.186.61.32:8080 type: string type: object + v1.UpdateTaskBackupStrategyReq: + properties: + strategy: + type: string + type: object v1.UpdateWechatConfigurationReqV1: properties: corp_id: @@ -5162,12 +5201,18 @@ definitions: type: array audit_status: type: string + backup_strategy: + type: string + backup_strategy_tip: + type: string description: type: string exec_result: type: string exec_sql: type: string + exec_sql_id: + type: integer exec_status: type: string number: @@ -5197,6 +5242,8 @@ definitions: type: object v2.CreateWorkflowReqV2: properties: + associated_workflow_id: + type: string desc: type: string sql_version_id: @@ -10103,6 +10150,10 @@ paths: in: formData name: instance_schema type: string + - description: enable backup + in: formData + name: enable_backup + type: boolean - description: sqls for audit in: formData name: sql @@ -10314,6 +10365,48 @@ paths: summary: 创建工单 tags: - workflow + /v1/projects/{project_name}/workflows/{workflow_id}/backup_sqls: + get: + description: get backup sql list + operationId: GetBackupSqlListV1 + parameters: + - description: 'filter: exec status of task sql' + enum: + - initialized + - doing + - succeeded + - failed + - manually_executed + - terminating + - terminate_succeeded + - terminate_failed + in: query + name: filter_exec_status + type: string + - description: 'filter: instance id in workflow' + in: query + name: filter_instance_id + type: integer + - description: page index + in: query + name: page_index + required: true + type: string + - description: page size + in: query + name: page_size + required: true + type: string + responses: + "200": + description: OK + schema: + $ref: '#/definitions/v1.BackupSqlListRes' + security: + - ApiKeyAuth: [] + summary: 获取工单下所有回滚SQL的列表 + tags: + - workflow /v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/attachment: get: description: get workflow attachment @@ -10344,6 +10437,36 @@ paths: summary: 获取工单的task附件 tags: - workflow + /v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/backup_files/download: + get: + description: download SQL back up file for the audit task + operationId: downloadBackupFileV1 + parameters: + - description: workflow id + in: path + name: workflow_id + required: true + type: string + - description: project name + in: path + name: project_name + required: true + type: string + - description: task id + in: path + name: task_id + required: true + type: string + responses: + "200": + description: sql file + schema: + type: file + security: + - ApiKeyAuth: [] + summary: 下载工单中的SQL备份 + tags: + - task /v1/projects/{project_name}/workflows/{workflow_id}/tasks/{task_id}/order_file: post: consumes: @@ -11570,6 +11693,10 @@ paths: in: formData name: sql type: string + - description: enable backup + in: formData + name: enable_backup + type: boolean - description: file order method in: formData name: file_order_method @@ -11618,6 +11745,35 @@ paths: summary: 获取Sql扫描任务信息 tags: - task + patch: + consumes: + - application/json + description: update back up strategy for all sqls in task + operationId: UpdateTaskBackupStrategyV1 + parameters: + - description: task id + in: path + name: task_id + required: true + type: string + - description: update back up strategy for sqls in workflow + in: body + name: strategy + required: true + schema: + $ref: '#/definitions/v1.UpdateTaskBackupStrategyReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controller.BaseRes' + security: + - ApiKeyAuth: [] + summary: 更新工单中数据源对应所有SQL的备份策略 + tags: + - workflow /v1/tasks/audits/{task_id}/origin_file: get: description: get SQL origin file of the audit task @@ -11823,6 +11979,41 @@ paths: summary: 获取task相关的SQL执行计划和表元数据 tags: - task + /v1/tasks/audits/{task_id}/sqls/{sql_id}/: + patch: + consumes: + - application/json + description: update back up strategy for one sql in workflow + operationId: UpdateSqlBackupStrategyV1 + parameters: + - description: task id + in: path + name: task_id + required: true + type: string + - description: sql id + in: path + name: sql_id + required: true + type: string + - description: update back up strategy for one sql in workflow + in: body + name: strategy + required: true + schema: + $ref: '#/definitions/v1.UpdateSqlBackupStrategyReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/controller.BaseRes' + security: + - ApiKeyAuth: [] + summary: 更新单条SQL的备份策略 + tags: + - workflow /v1/tasks/file_order_methods: get: consumes: @@ -12358,7 +12549,7 @@ paths: $ref: '#/definitions/controller.BaseRes' security: - ApiKeyAuth: [] - summary: 更新工单(驳回后才可更新) + summary: 更新工单(工单被驳回、工单被关闭、执行成功、执行失败后才可更新) tags: - workflow /v2/projects/{project_name}/workflows/{workflow_id}/cancel: