Skip to content

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

Add code column to task_run and make task_run table display custom action based on the code

天舟a4fd5868a6ef
diff --git a/api/task.go b/api/task.go
index 07f5790b20..f9e78c52e3 100644
--- a/api/task.go
+++ b/api/task.go
@@ -183,7 +183,8 @@ type TaskStatusPatch struct {
// Domain specific fields
Status TaskStatus `jsonapi:"attr,status"`
- Comment string `jsonapi:"attr,comment"`
+ Code *common.Code
+ Comment *string `jsonapi:"attr,comment"`
}
type TaskService interface {
diff --git a/api/task_run.go b/api/task_run.go
index 5c250d0e42..300c7e1ae7 100644
--- a/api/task_run.go
+++ b/api/task_run.go
@@ -4,6 +4,8 @@ import (
"context"
"database/sql"
"encoding/json"
+
+ "github.com/bytebase/bytebase/common"
)
type TaskRunStatus string
@@ -48,6 +50,7 @@ type TaskRun struct {
Name string `jsonapi:"attr,name"`
Status TaskRunStatus `jsonapi:"attr,status"`
Type TaskType `jsonapi:"attr,type"`
+ Code common.Code `jsonapi:"attr,code"`
Comment string `jsonapi:"attr,comment"`
Payload string `jsonapi:"attr,payload"`
}
@@ -95,8 +98,9 @@ type TaskRunStatusPatch struct {
// Domain specific fields
Status TaskRunStatus
+ Code *common.Code
// Records the status detail (e.g. error message on failure)
- Comment string
+ Comment *string
}
type TaskRunService interface {
diff --git a/common/error.go b/common/error.go
index dc94f0f848..182e7a3485 100644
--- a/common/error.go
+++ b/common/error.go
@@ -2,7 +2,6 @@ package common
import (
"errors"
- "fmt"
)
type Code int
@@ -22,6 +21,12 @@ const (
DbConnectionFailure Code = 101
DbStatementSyntaxError Code = 102
DbExecutionError Code = 103
+
+ // 201 db migration error
+ // Db migration is a core feature, so we separate it from the db error
+ MigrationAlreadyApplied Code = 201
+ MigrationOutOfOrder Code = 202
+ MigrationBaselineMissing Code = 203
)
// Error represents an application-specific error. Application errors can be
@@ -41,7 +46,7 @@ type Error struct {
// Error implements the error interface. Not used by the application otherwise.
func (e *Error) Error() string {
- return fmt.Sprintf("bytebase error: code=%d message=%v", e.Code, e.Err)
+ return e.Err.Error()
}
// ErrorCode unwraps an application error and returns its code.
diff --git a/frontend/src/components/IssueStagePanel.vue b/frontend/src/components/IssueStagePanel.vue
index 88068d24d9..e275fe0345 100644
--- a/frontend/src/components/IssueStagePanel.vue
+++ b/frontend/src/components/IssueStagePanel.vue
@@ -20,7 +20,7 @@
{{ task.name }}
</div>
</div>
- <TaskRunTable :taskRunList="task.taskRunList" />
+ <TaskRunTable :task="task" />
</div>
</div>
</template>
diff --git a/frontend/src/components/TaskRunTable.vue b/frontend/src/components/TaskRunTable.vue
index 2e22151dce..4729f22436 100644
--- a/frontend/src/components/TaskRunTable.vue
+++ b/frontend/src/components/TaskRunTable.vue
@@ -1,7 +1,7 @@
<template>
<BBTable
:columnList="columnList"
- :dataSource="taskRunList"
+ :dataSource="task.taskRunList"
:showHeader="true"
:leftBordered="true"
:rightBordered="true"
@@ -72,6 +72,13 @@
</BBTableCell>
<BBTableCell class="table-cell w-36">
{{ taskRun.comment }}
+ <template v-if="commentLink(taskRun).link">
+ <router-link
+ class="ml-1 normal-link"
+ :to="commentLink(taskRun).link"
+ >{{ commentLink(taskRun).title }}</router-link
+ >
+ </template>
</BBTableCell>
<BBTableCell class="table-cell w-12">
<div class="flex flex-row items-center space-x-2">
@@ -99,7 +106,14 @@
import { PropType } from "vue";
import PrincipalAvatar from "./PrincipalAvatar.vue";
import { BBTableColumn } from "../bbkit/types";
-import { TaskRun, TaskRunStatus } from "../types";
+import { MigrationErrorCode, Task, TaskRun, TaskRunStatus } from "../types";
+import { useStore } from "vuex";
+import { databaseSlug } from "../utils";
+
+type CommentLink = {
+ title: string;
+ link: string;
+};
const columnList: BBTableColumn[] = [
{
@@ -123,12 +137,14 @@ export default {
name: "TaskRunTable",
components: { PrincipalAvatar },
props: {
- taskRunList: {
+ task: {
required: true,
- type: Object as PropType<TaskRun[]>,
+ type: Object as PropType<Task>,
},
},
setup(props, ctx) {
+ const store = useStore();
+
const statusIconClass = (status: TaskRunStatus) => {
switch (status) {
case "RUNNING":
@@ -142,9 +158,22 @@ export default {
}
};
+ const commentLink = (taskRun: TaskRun): CommentLink | undefined => {
+ if (taskRun.status == "FAILED") {
+ if (taskRun.code == MigrationErrorCode.MIGRATION_BASELINE_MISSING) {
+ return {
+ title: "view migration history",
+ link: `/db/${databaseSlug(props.task.database!)}#migration-history`,
+ };
+ }
+ }
+ return undefined;
+ };
+
return {
columnList,
statusIconClass,
+ commentLink,
};
},
};
diff --git a/frontend/src/types/error.ts b/frontend/src/types/error.ts
index 9b9853aa16..b225db62da 100644
--- a/frontend/src/types/error.ts
+++ b/frontend/src/types/error.ts
@@ -14,4 +14,10 @@ export enum DBErrorCode {
EXECUTION_ERROR = 103,
}
-export type ErrorCode = GeneralErrorCode | DBErrorCode;
+export enum MigrationErrorCode {
+ MIGRAITON_ALREADY_APPLIED = 201,
+ MGIRATION_OUT_OF_ORDER = 202,
+ MIGRATION_BASELINE_MISSING = 203,
+}
+
+export type ErrorCode = GeneralErrorCode | DBErrorCode | MigrationErrorCode;
diff --git a/frontend/src/types/pipeline/task.ts b/frontend/src/types/pipeline/task.ts
index a09cfaed21..90bcf905a6 100644
--- a/frontend/src/types/pipeline/task.ts
+++ b/frontend/src/types/pipeline/task.ts
@@ -125,6 +125,7 @@ export type TaskRun = {
name: string;
status: TaskRunStatus;
type: TaskType;
+ code: ErrorCode;
comment: string;
payload?: TaskPayload;
};
diff --git a/plugin/db/mysql/mysql.go b/plugin/db/mysql/mysql.go
index d72b57838b..3b0830be3e 100644
--- a/plugin/db/mysql/mysql.go
+++ b/plugin/db/mysql/mysql.go
@@ -511,7 +511,7 @@ func (driver *Driver) ExecuteMigration(ctx context.Context, m *db.MigrationInfo,
return "", err
}
if duplicate {
- return "", fmt.Errorf("database %q has already applied version %s", m.Database, m.Version)
+ return "", common.Errorf(common.MigrationAlreadyApplied, fmt.Errorf("database %q has already applied version %s", m.Database, m.Version))
}
// Check if there is any higher version already been applied
@@ -520,7 +520,7 @@ func (driver *Driver) ExecuteMigration(ctx context.Context, m *db.MigrationInfo,
return "", err
}
if version != nil {
- return "", fmt.Errorf("database %q has already applied version %s which is higher than %s", m.Database, *version, m.Version)
+ return "", common.Errorf(common.MigrationOutOfOrder, fmt.Errorf("database %q has already applied version %s which is higher than %s", m.Database, *version, m.Version))
}
// If the migration engine is VCS and type is not baseline and is not branch, then we can only proceed if there is existing baseline
@@ -532,7 +532,7 @@ func (driver *Driver) ExecuteMigration(ctx context.Context, m *db.MigrationInfo,
}
if !hasBaseline {
- return "", fmt.Errorf("%s has not created migration baseline yet", m.Database)
+ return "", common.Errorf(common.MigrationBaselineMissing, fmt.Errorf("%s has not created migration baseline yet", m.Database))
}
}
@@ -836,7 +836,7 @@ func findNextSequence(ctx context.Context, tx *sql.Tx, namespace string, require
}
// This should not happen normally since we already check the baselining exist beforehand. Just in case.
- return -1, fmt.Errorf("unable to generate next migration_sequence, no migration hisotry found for %q, do you forget to baselining?", namespace)
+ return -1, common.Errorf(common.MigrationBaselineMissing, fmt.Errorf("unable to generate next migration_sequence, no migration hisotry found for %q, do you forget to baselining?", namespace))
}
return int(sequence.Int32), nil
diff --git a/server/task.go b/server/task.go
index bfddd4fbc5..ddc2d8c41b 100644
--- a/server/task.go
+++ b/server/task.go
@@ -370,10 +370,12 @@ func (s *Server) ChangeTaskStatusWithPatch(ctx context.Context, task *api.Task,
CreatorId: taskStatusPatch.UpdaterId,
ContainerId: containerId,
Type: api.ActivityPipelineTaskStatusUpdate,
- Comment: taskStatusPatch.Comment,
Level: level,
Payload: string(payload),
}
+ if taskStatusPatch.Comment != nil {
+ activityCreate.Comment = *taskStatusPatch.Comment
+ }
activityMeta := ActivityMeta{}
if issue != nil {
diff --git a/server/task_scheduler.go b/server/task_scheduler.go
index 2fff99083f..d2c926a5c8 100644
--- a/server/task_scheduler.go
+++ b/server/task_scheduler.go
@@ -7,6 +7,7 @@ import (
"time"
"github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
"go.uber.org/zap"
)
@@ -122,11 +123,13 @@ func (s *TaskScheduler) Run() error {
done, detail, err := executor.RunOnce(context.Background(), s.server, task)
if done {
if err == nil {
+ code := common.Ok
taskStatusPatch := &api.TaskStatusPatch{
ID: task.ID,
UpdaterId: api.SYSTEM_BOT_ID,
Status: api.TaskDone,
- Comment: detail,
+ Code: &code,
+ Comment: &detail,
}
_, err = s.server.ChangeTaskStatusWithPatch(context.Background(), task, taskStatusPatch)
if err != nil {
@@ -143,11 +146,14 @@ func (s *TaskScheduler) Run() error {
zap.String("type", string(task.Type)),
zap.Error(err),
)
+ code := common.ErrorCode(err)
+ comment := err.Error()
taskStatusPatch := &api.TaskStatusPatch{
ID: task.ID,
UpdaterId: api.SYSTEM_BOT_ID,
Status: api.TaskFailed,
- Comment: err.Error(),
+ Code: &code,
+ Comment: &comment,
}
_, err = s.server.ChangeTaskStatusWithPatch(context.Background(), task, taskStatusPatch)
if err != nil {
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index 14f33b4e31..631fd846e9 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -841,6 +841,7 @@ CREATE TABLE task_run (
)
),
`type` TEXT NOT NULL CHECK (`type` LIKE 'bb.task.%'),
+ code INTEGER NOT NULL DEFAULT 0,
comment TEXT NOT NULL DEFAULT '',
payload TEXT NOT NULL DEFAULT ''
);
diff --git a/store/seed/test/10120__task_run.sql b/store/seed/test/10120__task_run.sql
index a7b1044029..958a633700 100644
--- a/store/seed/test/10120__task_run.sql
+++ b/store/seed/test/10120__task_run.sql
@@ -9,6 +9,7 @@ INSERT INTO
name,
`status`,
`type`,
+ code,
comment,
payload
)
@@ -22,6 +23,7 @@ VALUES
'Add initial schema 1624873710',
'DONE',
'bb.task.database.schema.update',
+ 0,
'Established baseline version 202106280000 for database ''shop''',
'{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
);
@@ -37,6 +39,7 @@ INSERT INTO
name,
`status`,
`type`,
+ code,
comment,
payload
)
@@ -50,6 +53,7 @@ VALUES
'Add initial schema 1624883710',
'DONE',
'bb.task.database.schema.update',
+ 0,
'Established baseline version 202106280000 for database ''shop''',
'{"migrationType":"BASELINE","statement":"CREATE TABLE product (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tdescription TEXT NOT NULL\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"14","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/shop","repositoryFullPath":"bytebase-demo/shop","authorName":"tianzhou","fileCommit":{"id":"c80352facbaefcde0c1c82340381be3286e5438d","title":"Create product table","message":"Create product table","createdTs":1624873354,"url":"http://gitlab.bytebase.com/bytebase-demo/shop/-/commit/c80352facbaefcde0c1c82340381be3286e5438d","authorName":"tianzhou","added":"bytebase/shop__v1__baseline__add_initial_schema.sql"}}}'
);
@@ -64,6 +68,7 @@ INSERT INTO
name,
`status`,
`type`,
+ code,
comment
)
VALUES
@@ -75,6 +80,7 @@ VALUES
'Update testdb_dev task run',
'FAILED',
'bb.task.database.schema.update',
+ 103,
'table "tbl1" already exists'
);
@@ -89,6 +95,7 @@ INSERT INTO
name,
`status`,
`type`,
+ code,
comment,
payload
)
@@ -102,6 +109,7 @@ VALUES
'Add initial schema 1624865387',
'DONE',
'bb.task.database.schema.update',
+ 0,
'Established baseline version 202106280000 for database ''blog''',
'{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"d7f3b88b93c4d7f57b710980cdf92f72dcc4cd1e","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/d7f3b88b93c4d7f57b710980cdf92f72dcc4cd1e","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
);
@@ -117,6 +125,7 @@ INSERT INTO
name,
`status`,
`type`,
+ code,
comment,
payload
)
@@ -130,6 +139,7 @@ VALUES
'Add initial schema 1624866790',
'DONE',
'bb.task.database.schema.update',
+ 0,
'Established baseline version 202106280000 for database ''blog''',
'{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
);
@@ -145,6 +155,7 @@ INSERT INTO
name,
`status`,
`type`,
+ code,
comment,
payload
)
@@ -158,6 +169,7 @@ VALUES
'Add initial schema 1624868407',
'DONE',
'bb.task.database.schema.update',
+ 0,
'Established baseline version 202106280000 for database ''blog''',
'{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
);
@@ -173,6 +185,7 @@ INSERT INTO
name,
`status`,
`type`,
+ code,
comment,
payload
)
@@ -186,6 +199,7 @@ VALUES
'Add initial schema 1624868680',
'DONE',
'bb.task.database.schema.update',
+ 0,
'Established baseline version 202106280000 for database ''blog''',
'{"migrationType":"BASELINE","statement":"CREATE TABLE `user` (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\temail TEXT NOT NULL\n);\n\nCREATE TABLE post (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tname TEXT NOT NULL,\n\tcontent TEXT NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n\nCREATE TABLE comment (\n\tid INTEGER PRIMARY KEY AUTO_INCREMENT,\n\tcontent TEXT NOT NULL,\n\tpost_id INTEGER NOT NULL,\n\tauthor_id INTEGER NOT NULL,\n\tFOREIGN KEY (post_id) REFERENCES post (id) ON DELETE CASCADE,\n\tFOREIGN KEY (author_id) REFERENCES `user` (id) ON DELETE RESTRICT\n);\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8f578d53e821c46421d69fd0aabd29921190a6c0","title":"Create user, post, comment table for dev environment","message":"Create user, post, comment table for dev environment","createdTs":1624865383,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8f578d53e821c46421d69fd0aabd29921190a6c0","authorName":"tianzhou","added":"bytebase/dev/blog__202106280000__baseline__add_initial_schema.sql"}}}'
);
@@ -201,6 +215,7 @@ INSERT INTO
name,
`status`,
`type`,
+ code,
comment,
payload
)
@@ -214,6 +229,7 @@ VALUES
'Add created at column 1624869944',
'FAILED',
'bb.task.database.schema.update',
+ 201,
'database ''blog'' has already applied version 202106280100',
'{"migrationType":"MIGRATE","statement":"ALTER TABLE `user` ADD COLUMN `created_at` DATETIME NOT NULL;\n\nALTER TABLE post ADD COLUMN `created_at` DATETIME NOT NULL;\n\nALTER TABLE comment ADD COLUMN `created_at` DATETIME NOT NULL;\n","pushEvent":{"vcsType":"GITLAB_SELF_HOST","baseDir":"bytebase","ref":"refs/heads/master","repositoryId":"13","repositoryUrl":"http://gitlab.bytebase.com/bytebase-demo/blog","repositoryFullPath":"bytebase-demo/blog","authorName":"tianzhou","fileCommit":{"id":"8ff6482998059a861e1faa14658c65244577b54e","title":"Add created_at column to user,post,comment table for dev environment","message":"Add created_at column to user,post,comment table for dev environment","createdTs":1624869938,"url":"http://gitlab.bytebase.com/bytebase-demo/blog/-/commit/8ff6482998059a861e1faa14658c65244577b54e","authorName":"tianzhou","added":"bytebase/dev/blog__202106280100__migrate__add_created_at_column.sql"}}}'
);
@@ -229,6 +245,7 @@ INSERT INTO
name,
`status`,
`type`,
+ code,
comment,
payload
)
@@ -242,6 +259,7 @@ VALUES
'Update testdb_dev task run',
'DONE',
'bb.task.database.schema.update',
+ 0,
'Applied migration version 20210830011437.11013 to database "testdb_dev"',
'{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_dev.tbl2 (name TEXT)"}'
);
@@ -285,6 +303,7 @@ INSERT INTO
name,
`status`,
`type`,
+ code,
comment,
payload
)
@@ -298,6 +317,7 @@ VALUES
'Update testdb_staging task run',
'FAILED',
'bb.task.database.schema.update',
+ 103,
'table "tbl2" already exists',
'{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_staging.tbl2 (name TEXT)"}'
);
\ No newline at end of file
diff --git a/store/task.go b/store/task.go
index 81352af6af..b6f380baa2 100644
--- a/store/task.go
+++ b/store/task.go
@@ -419,6 +419,7 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.Ta
ID: &taskRun.ID,
UpdaterId: patch.UpdaterId,
TaskId: &patch.ID,
+ Code: patch.Code,
Comment: patch.Comment,
}
switch patch.Status {
diff --git a/store/task_run.go b/store/task_run.go
index ef5f2d4689..6d3d6ae115 100644
--- a/store/task_run.go
+++ b/store/task_run.go
@@ -39,7 +39,7 @@ func (s *TaskRunService) CreateTaskRunTx(ctx context.Context, tx *sql.Tx, create
payload
)
VALUES (?, ?, ?, ?, 'RUNNING', ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, `+"`status`, `type`, comment, payload"+`
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, `+"`status`, `type`, code, comment, payload"+`
`,
create.CreatorId,
create.CreatorId,
@@ -66,6 +66,7 @@ func (s *TaskRunService) CreateTaskRunTx(ctx context.Context, tx *sql.Tx, create
&taskRun.Name,
&taskRun.Status,
&taskRun.Type,
+ &taskRun.Code,
&taskRun.Comment,
&taskRun.Payload,
); err != nil {
@@ -105,7 +106,12 @@ func (s *TaskRunService) PatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, p
// Build UPDATE clause.
set, args := []string{"updater_id = ?"}, []interface{}{patch.UpdaterId}
set, args = append(set, "`status` = ?"), append(args, patch.Status)
- set, args = append(set, "comment = ?"), append(args, patch.Comment)
+ if v := patch.Code; v != nil {
+ set, args = append(set, "code = ?"), append(args, *v)
+ }
+ if v := patch.Comment; v != nil {
+ set, args = append(set, "comment = ?"), append(args, *v)
+ }
// Build WHERE clause.
where := []string{"1 = 1"}
@@ -120,7 +126,7 @@ func (s *TaskRunService) PatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, p
UPDATE task_run
SET `+strings.Join(set, ", ")+`
WHERE `+strings.Join(where, " AND ")+`
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, `+"`status`, `type`, comment, payload"+`
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, `+"`status`, `type`, code, comment, payload"+`
`,
args...,
)
@@ -142,6 +148,7 @@ func (s *TaskRunService) PatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, p
&taskRun.Name,
&taskRun.Status,
&taskRun.Type,
+ &taskRun.Code,
&taskRun.Comment,
&taskRun.Payload,
); err != nil {
@@ -181,6 +188,7 @@ func (s *TaskRunService) findTaskRunList(ctx context.Context, tx *sql.Tx, find *
name,
`+"`status`,"+`
`+"`type`,"+`
+ code,
comment,
payload
FROM task_run
@@ -206,6 +214,7 @@ func (s *TaskRunService) findTaskRunList(ctx context.Context, tx *sql.Tx, find *
&taskRun.Name,
&taskRun.Status,
&taskRun.Type,
+ &taskRun.Code,
&taskRun.Comment,
&taskRun.Payload,
); err != nil {