From 666493196d0d6582e979c2e2be3085247f5a55aa Mon Sep 17 00:00:00 2001 From: WinfredLIN Date: Tue, 19 Nov 2024 17:05:56 +0800 Subject: [PATCH 1/2] api definition: modify audit task resp and workflow resp 1. rollback sql to rollback sqls 2. associated workflow add name in it 3. add associated workflow in returns of workflow resp --- sqle/api/controller/v2/task.go | 39 +++++++++++++++++------------- sqle/api/controller/v2/workflow.go | 23 +++++++++--------- sqle/docs/docs.go | 28 ++++++++++++++++++--- sqle/docs/swagger.json | 28 ++++++++++++++++++--- sqle/docs/swagger.yaml | 21 +++++++++++++--- 5 files changed, 99 insertions(+), 40 deletions(-) diff --git a/sqle/api/controller/v2/task.go b/sqle/api/controller/v2/task.go index 547103e83..2be3e0c5d 100644 --- a/sqle/api/controller/v2/task.go +++ b/sqle/api/controller/v2/task.go @@ -28,22 +28,27 @@ type GetAuditTaskSQLsResV2 struct { } type AuditTaskSQLResV2 struct { - 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" enums:"none,manual,reverse_sql,origin_row"` - BackupStrategyTip string `json:"backup_strategy_tip"` - AssociatedWorkflowIds []string `json:"associate_workflow_ids"` + 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"` + RollbackSQLs []string `json:"rollback_sqls,omitempty"` + Description string `json:"description"` + SQLType string `json:"sql_type"` + BackupStrategy string `json:"backup_strategy" enums:"none,manual,reverse_sql,origin_row"` + BackupStrategyTip string `json:"backup_strategy_tip"` + AssociatedRollbackWorkflows []AssociatedRollbackWorkflow `json:"associated_rollback_workflows"` +} + +type AssociatedRollbackWorkflow struct { + WorkflowID string `json:"workflow_id"` + WorkflowName string `json:"workflow_name"` } type AuditResult struct { @@ -115,7 +120,7 @@ func GetTaskSQLs(c echo.Context) error { AuditStatus: taskSQL.AuditStatus, ExecResult: taskSQL.ExecResult, ExecStatus: taskSQL.ExecStatus, - RollbackSQL: taskSQL.RollbackSQL.String, + RollbackSQLs: []string{taskSQL.RollbackSQL.String}, SQLType: taskSQL.SQLType.String, } for i := range taskSQL.AuditResults { diff --git a/sqle/api/controller/v2/workflow.go b/sqle/api/controller/v2/workflow.go index 252aba5d6..d50747ab2 100644 --- a/sqle/api/controller/v2/workflow.go +++ b/sqle/api/controller/v2/workflow.go @@ -1134,17 +1134,18 @@ type WorkflowRecordResV2 struct { } type WorkflowResV2 struct { - Name string `json:"workflow_name"` - WorkflowID string `json:"workflow_id"` - Desc string `json:"desc,omitempty"` - Mode string `json:"mode" enums:"same_sqls,different_sqls"` - ExecMode string `json:"exec_mode" enums:"sql_file,sqls"` - CreateUser string `json:"create_user_name"` - CreateTime *time.Time `json:"create_time"` - SqlVersion *SqlVersion `json:"sql_version,omitempty"` - Record *WorkflowRecordResV2 `json:"record"` - RecordHistory []*WorkflowRecordResV2 `json:"record_history_list,omitempty"` - AssociatedStageWorkflows []*AssociatedStageWorkflows `json:"associated_stage_workflows,omitempty"` + Name string `json:"workflow_name"` + WorkflowID string `json:"workflow_id"` + Desc string `json:"desc,omitempty"` + Mode string `json:"mode" enums:"same_sqls,different_sqls"` + ExecMode string `json:"exec_mode" enums:"sql_file,sqls"` + CreateUser string `json:"create_user_name"` + CreateTime *time.Time `json:"create_time"` + SqlVersion *SqlVersion `json:"sql_version,omitempty"` + Record *WorkflowRecordResV2 `json:"record"` + RecordHistory []*WorkflowRecordResV2 `json:"record_history_list,omitempty"` + AssociatedStageWorkflows []*AssociatedStageWorkflows `json:"associated_stage_workflows,omitempty"` + AssociatedRollbackWorkflows []*AssociatedRollbackWorkflow `json:"associated_rollback_workflows"` } type AssociatedStageWorkflows struct { diff --git a/sqle/docs/docs.go b/sqle/docs/docs.go index a0ed1f508..5f9a1b6c8 100644 --- a/sqle/docs/docs.go +++ b/sqle/docs/docs.go @@ -18510,6 +18510,17 @@ var doc = `{ } } }, + "v2.AssociatedRollbackWorkflow": { + "type": "object", + "properties": { + "workflow_id": { + "type": "string" + }, + "workflow_name": { + "type": "string" + } + } + }, "v2.AssociatedStageWorkflows": { "type": "object", "properties": { @@ -18775,10 +18786,10 @@ var doc = `{ "v2.AuditTaskSQLResV2": { "type": "object", "properties": { - "associate_workflow_ids": { + "associated_rollback_workflows": { "type": "array", "items": { - "type": "string" + "$ref": "#/definitions/v2.AssociatedRollbackWorkflow" } }, "audit_level": { @@ -18823,8 +18834,11 @@ var doc = `{ "number": { "type": "integer" }, - "rollback_sql": { - "type": "string" + "rollback_sqls": { + "type": "array", + "items": { + "type": "string" + } }, "sql_source_file": { "type": "string" @@ -19639,6 +19653,12 @@ var doc = `{ "v2.WorkflowResV2": { "type": "object", "properties": { + "associated_rollback_workflows": { + "type": "array", + "items": { + "$ref": "#/definitions/v2.AssociatedRollbackWorkflow" + } + }, "associated_stage_workflows": { "type": "array", "items": { diff --git a/sqle/docs/swagger.json b/sqle/docs/swagger.json index 78549f2e3..d45f83750 100644 --- a/sqle/docs/swagger.json +++ b/sqle/docs/swagger.json @@ -18494,6 +18494,17 @@ } } }, + "v2.AssociatedRollbackWorkflow": { + "type": "object", + "properties": { + "workflow_id": { + "type": "string" + }, + "workflow_name": { + "type": "string" + } + } + }, "v2.AssociatedStageWorkflows": { "type": "object", "properties": { @@ -18759,10 +18770,10 @@ "v2.AuditTaskSQLResV2": { "type": "object", "properties": { - "associate_workflow_ids": { + "associated_rollback_workflows": { "type": "array", "items": { - "type": "string" + "$ref": "#/definitions/v2.AssociatedRollbackWorkflow" } }, "audit_level": { @@ -18807,8 +18818,11 @@ "number": { "type": "integer" }, - "rollback_sql": { - "type": "string" + "rollback_sqls": { + "type": "array", + "items": { + "type": "string" + } }, "sql_source_file": { "type": "string" @@ -19623,6 +19637,12 @@ "v2.WorkflowResV2": { "type": "object", "properties": { + "associated_rollback_workflows": { + "type": "array", + "items": { + "$ref": "#/definitions/v2.AssociatedRollbackWorkflow" + } + }, "associated_stage_workflows": { "type": "array", "items": { diff --git a/sqle/docs/swagger.yaml b/sqle/docs/swagger.yaml index 8c7e8a250..00382ae4d 100644 --- a/sqle/docs/swagger.yaml +++ b/sqle/docs/swagger.yaml @@ -5078,6 +5078,13 @@ definitions: err_message: type: string type: object + v2.AssociatedRollbackWorkflow: + properties: + workflow_id: + type: string + workflow_name: + type: string + type: object v2.AssociatedStageWorkflows: properties: sql_version_stage_id: @@ -5263,9 +5270,9 @@ definitions: type: object v2.AuditTaskSQLResV2: properties: - associate_workflow_ids: + associated_rollback_workflows: items: - type: string + $ref: '#/definitions/v2.AssociatedRollbackWorkflow' type: array audit_level: type: string @@ -5296,8 +5303,10 @@ definitions: type: string number: type: integer - rollback_sql: - type: string + rollback_sqls: + items: + type: string + type: array sql_source_file: type: string sql_start_line: @@ -5857,6 +5866,10 @@ definitions: type: object v2.WorkflowResV2: properties: + associated_rollback_workflows: + items: + $ref: '#/definitions/v2.AssociatedRollbackWorkflow' + type: array associated_stage_workflows: items: $ref: '#/definitions/v2.AssociatedStageWorkflows' From 8512f2bda677b785eb7c60cf28ff7d9780be4465 Mon Sep 17 00:00:00 2001 From: WinfredLIN Date: Wed, 20 Nov 2024 15:13:52 +0800 Subject: [PATCH 2/2] api definition: add omit empty --- sqle/api/controller/v2/task.go | 32 +++++++++++++++--------------- sqle/api/controller/v2/workflow.go | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/sqle/api/controller/v2/task.go b/sqle/api/controller/v2/task.go index 2be3e0c5d..bc7888a5d 100644 --- a/sqle/api/controller/v2/task.go +++ b/sqle/api/controller/v2/task.go @@ -28,22 +28,22 @@ type GetAuditTaskSQLsResV2 struct { } type AuditTaskSQLResV2 struct { - 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"` - RollbackSQLs []string `json:"rollback_sqls,omitempty"` - Description string `json:"description"` - SQLType string `json:"sql_type"` - BackupStrategy string `json:"backup_strategy" enums:"none,manual,reverse_sql,origin_row"` - BackupStrategyTip string `json:"backup_strategy_tip"` - AssociatedRollbackWorkflows []AssociatedRollbackWorkflow `json:"associated_rollback_workflows"` + 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"` + RollbackSQLs []string `json:"rollback_sqls,omitempty"` + Description string `json:"description"` + SQLType string `json:"sql_type"` + BackupStrategy string `json:"backup_strategy" enums:"none,manual,reverse_sql,origin_row"` + BackupStrategyTip string `json:"backup_strategy_tip"` + AssociatedRollbackWorkflows []*AssociatedRollbackWorkflow `json:"associated_rollback_workflows"` } type AssociatedRollbackWorkflow struct { diff --git a/sqle/api/controller/v2/workflow.go b/sqle/api/controller/v2/workflow.go index d50747ab2..e7711dbfb 100644 --- a/sqle/api/controller/v2/workflow.go +++ b/sqle/api/controller/v2/workflow.go @@ -1145,7 +1145,7 @@ type WorkflowResV2 struct { Record *WorkflowRecordResV2 `json:"record"` RecordHistory []*WorkflowRecordResV2 `json:"record_history_list,omitempty"` AssociatedStageWorkflows []*AssociatedStageWorkflows `json:"associated_stage_workflows,omitempty"` - AssociatedRollbackWorkflows []*AssociatedRollbackWorkflow `json:"associated_rollback_workflows"` + AssociatedRollbackWorkflows []*AssociatedRollbackWorkflow `json:"associated_rollback_workflows,omitempty"` } type AssociatedStageWorkflows struct {