Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Add code to task_check_run

天舟85473643fb07
diff --git a/api/task_check_run.go b/api/task_check_run.go
index 990bfb94a4..5c1f613d55 100644
--- a/api/task_check_run.go
+++ b/api/task_check_run.go
@@ -97,6 +97,7 @@ type TaskCheckRun struct {
// Domain specific fields
Status TaskCheckRunStatus `jsonapi:"attr,status"`
Type TaskCheckType `jsonapi:"attr,type"`
+ Code common.Code `jsonapi:"attr,code"`
Comment string `jsonapi:"attr,comment"`
Result string `jsonapi:"attr,result"`
Payload string `jsonapi:"attr,payload"`
@@ -151,6 +152,7 @@ type TaskCheckRunStatusPatch struct {
// Domain specific fields
Status TaskCheckRunStatus
+ Code common.Code
// Records the status detail (e.g. error message on failure)
Comment string
Result string
diff --git a/frontend/src/components/TaskCheckRunPanel.vue b/frontend/src/components/TaskCheckRunPanel.vue
index b6499e1af7..c93e4b9db7 100644
--- a/frontend/src/components/TaskCheckRunPanel.vue
+++ b/frontend/src/components/TaskCheckRunPanel.vue
@@ -125,6 +125,7 @@ export default {
{
status: "ERROR",
title: "Error",
+ code: props.taskCheckRun.code,
content: props.taskCheckRun.comment,
},
];
@@ -133,6 +134,7 @@ export default {
{
status: "WARN",
title: "Canceled",
+ code: props.taskCheckRun.code,
content: "",
},
];
diff --git a/frontend/src/types/pipeline/task.ts b/frontend/src/types/pipeline/task.ts
index b4fd526253..a09cfaed21 100644
--- a/frontend/src/types/pipeline/task.ts
+++ b/frontend/src/types/pipeline/task.ts
@@ -166,6 +166,7 @@ export type TaskCheckRun = {
taskId: TaskId;
status: TaskCheckRunStatus;
type: TaskCheckType;
+ code: ErrorCode;
comment: string;
result: TaskCheckRunResultPayload;
payload?: TaskPayload;
diff --git a/server/task_check_scheduler.go b/server/task_check_scheduler.go
index 9adb017d63..9ac3b6cf3e 100644
--- a/server/task_check_scheduler.go
+++ b/server/task_check_scheduler.go
@@ -7,6 +7,7 @@ import (
"time"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -96,6 +97,7 @@ func (s *TaskCheckScheduler) Run() error {
ID: &taskCheckRun.ID,
UpdaterId: api.SYSTEM_BOT_ID,
Status: api.TaskCheckRunDone,
+ Code: common.Ok,
Result: string(bytes),
}
_, err = s.server.TaskCheckRunService.PatchTaskCheckRunStatus(context.Background(), taskCheckRunStatusPatch)
@@ -118,6 +120,7 @@ func (s *TaskCheckScheduler) Run() error {
ID: &taskCheckRun.ID,
UpdaterId: api.SYSTEM_BOT_ID,
Status: api.TaskCheckRunFailed,
+ Code: common.Internal,
Comment: err.Error(),
}
_, err = s.server.TaskCheckRunService.PatchTaskCheckRunStatus(context.Background(), taskCheckRunStatusPatch)
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index fbc1a6ce2d..14f33b4e31 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -882,6 +882,7 @@ CREATE TABLE task_check_run (
)
),
`type` TEXT NOT NULL CHECK (`type` LIKE 'bb.task-check.%'),
+ code INTEGER NOT NULL DEFAULT 0,
comment TEXT NOT NULL DEFAULT '',
-- result saves the task check run result in json format
result TEXT NOT NULL DEFAULT '',
diff --git a/store/seed/test/10121__task_check_run.sql b/store/seed/test/10121__task_check_run.sql
index a0ec2e5c4b..26dc81682e 100644
--- a/store/seed/test/10121__task_check_run.sql
+++ b/store/seed/test/10121__task_check_run.sql
@@ -6,6 +6,7 @@ INSERT INTO
task_id,
`status`,
`type`,
+ code,
comment,
result,
payload
@@ -17,6 +18,7 @@ VALUES
11004,
'FAILED',
'bb.task-check.database.connect',
+ 101,
'failed to connect database "shop": failed to connect database On-premises Staging MySQL/shop at "mysql.staging.example.com":"3306" with user "admin": dial tcp: lookup mysql.staging.example.com: no such host',
'',
''
@@ -29,6 +31,7 @@ INSERT INTO
task_id,
`status`,
`type`,
+ code,
comment,
result,
payload
@@ -40,6 +43,7 @@ VALUES
11004,
'DONE',
'bb.task-check.database.statement.syntax',
+ 0,
'',
'{"resultList":[{"status":"SUCCESS","code":0,"title":"Syntax OK","content":"OK"}]}',
'{"statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","dbType":"MYSQL","charset":"utf8mb4","collation":"utf8mb4_general_ci"}'
diff --git a/store/task_check_run.go b/store/task_check_run.go
index e555b651bb..071ac23ea1 100644
--- a/store/task_check_run.go
+++ b/store/task_check_run.go
@@ -102,7 +102,7 @@ func (s *TaskCheckRunService) CreateTaskCheckRunTx(ctx context.Context, tx *sql.
payload
)
VALUES (?, ?, ?, 'RUNNING', ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, `+"`status`, `type`, comment, result, payload"+`
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, `+"`status`, `type`, code, comment, result, payload"+`
`,
create.CreatorId,
create.CreatorId,
@@ -128,6 +128,7 @@ func (s *TaskCheckRunService) CreateTaskCheckRunTx(ctx context.Context, tx *sql.
&taskCheckRun.TaskId,
&taskCheckRun.Status,
&taskCheckRun.Type,
+ &taskCheckRun.Code,
&taskCheckRun.Comment,
&taskCheckRun.Result,
&taskCheckRun.Payload,
@@ -204,6 +205,7 @@ func (s *TaskCheckRunService) PatchTaskCheckRunStatusTx(ctx context.Context, tx
// Build UPDATE clause.
set, args := []string{"updater_id = ?"}, []interface{}{patch.UpdaterId}
set, args = append(set, "`status` = ?"), append(args, patch.Status)
+ set, args = append(set, "code = ?"), append(args, patch.Code)
set, args = append(set, "comment = ?"), append(args, patch.Comment)
set, args = append(set, "result = ?"), append(args, patch.Result)
@@ -217,7 +219,7 @@ func (s *TaskCheckRunService) PatchTaskCheckRunStatusTx(ctx context.Context, tx
UPDATE task_check_run
SET `+strings.Join(set, ", ")+`
WHERE `+strings.Join(where, " AND ")+`
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, `+"`status`, `type`, comment, result, payload"+`
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, `+"`status`, `type`, code, comment, result, payload"+`
`,
args...,
)
@@ -238,6 +240,7 @@ func (s *TaskCheckRunService) PatchTaskCheckRunStatusTx(ctx context.Context, tx
&taskCheckRun.TaskId,
&taskCheckRun.Status,
&taskCheckRun.Type,
+ &taskCheckRun.Code,
&taskCheckRun.Comment,
&taskCheckRun.Result,
&taskCheckRun.Payload,
@@ -284,6 +287,7 @@ func (s *TaskCheckRunService) findTaskCheckRunList(ctx context.Context, tx *sql.
task_id,
`+"`status`,"+`
`+"`type`,"+`
+ code,
comment,
result,
payload
@@ -309,6 +313,7 @@ func (s *TaskCheckRunService) findTaskCheckRunList(ctx context.Context, tx *sql.
&taskCheckRun.TaskId,
&taskCheckRun.Status,
&taskCheckRun.Type,
+ &taskCheckRun.Code,
&taskCheckRun.Comment,
&taskCheckRun.Result,
&taskCheckRun.Payload,