Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Add result column to task_run table
天舟7c3668e282af
diff --git a/api/task.go b/api/task.goindex f9e78c52e3..80b447c542 100644--- a/api/task.go+++ b/api/task.go@@ -185,6 +185,7 @@ type TaskStatusPatch struct {Status TaskStatus `jsonapi:"attr,status"`Code *common.CodeComment *string `jsonapi:"attr,comment"`+ Result *string}type TaskService interface {diff --git a/api/task_run.go b/api/task_run.goindex 300c7e1ae7..1830176cd0 100644--- a/api/task_run.go+++ b/api/task_run.go@@ -32,6 +32,12 @@ func (e TaskRunStatus) String() string {return "UNKNOWN"}+type TaskRunResultPayload struct {+ Detail string `json:"detail,omitempty"`+ MigrationId int64 `json:"migrationId,omitempty"`+ Version string `json:"version,omitempty"`+}+type TaskRun struct {ID int `jsonapi:"primary,taskRun"`@@ -52,6 +58,7 @@ type TaskRun struct {Type TaskType `jsonapi:"attr,type"`Code common.Code `jsonapi:"attr,code"`Comment string `jsonapi:"attr,comment"`+ Result string `jsonapi:"attr,result"`Payload string `jsonapi:"attr,payload"`}@@ -101,6 +108,7 @@ type TaskRunStatusPatch struct {Code *common.Code// Records the status detail (e.g. error message on failure)Comment *string+ Result *string}type TaskRunService interface {diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.tsindex 2e6aa7d4e0..bae6741416 100644--- a/frontend/src/store/modules/task.ts+++ b/frontend/src/store/modules/task.ts@@ -27,13 +27,17 @@ function convertTaskRun(includedList: ResourceObject[],rootGetters: any): TaskRun {+ const result = taskRun.attributes.result+ ? JSON.parse((taskRun.attributes.result as string) || "{}")+ : {};const payload = taskRun.attributes.payload? JSON.parse((taskRun.attributes.payload as string) || "{}"): {};return {- ...(taskRun.attributes as Omit<TaskRun, "id" | "payload">),+ ...(taskRun.attributes as Omit<TaskRun, "id" | "result" | "payload">),id: parseInt(taskRun.id),+ result,payload,};}diff --git a/frontend/src/types/pipeline/task.ts b/frontend/src/types/pipeline/task.tsindex 90bcf905a6..ab43c067c4 100644--- a/frontend/src/types/pipeline/task.ts+++ b/frontend/src/types/pipeline/task.ts@@ -1,4 +1,4 @@-import { ErrorCode, TaskCheckRunId } from "..";+import { ErrorCode, MigrationHistoryId, TaskCheckRunId } from "..";import { Database } from "../database";import {BackupId,@@ -112,6 +112,12 @@ export type TaskStatusPatch = {// TaskRun is one run of a particular taskexport type TaskRunStatus = "RUNNING" | "DONE" | "FAILED" | "CANCELED";+export type TaskRunResultPayload = {+ detail: string;+ migrationId?: MigrationHistoryId;+ version?: string;+};+export type TaskRun = {id: TaskRunId;@@ -127,6 +133,7 @@ export type TaskRun = {type: TaskType;code: ErrorCode;comment: string;+ result: TaskRunResultPayload;payload?: TaskPayload;};diff --git a/frontend/src/utils/slug.ts b/frontend/src/utils/slug.tsindex 36dd78eefa..667f630666 100644--- a/frontend/src/utils/slug.ts+++ b/frontend/src/utils/slug.ts@@ -5,7 +5,7 @@ import {Environment,Instance,IssueId,- MigrationHistory,+ MigrationHistoryId,Project,ProjectWebhook,Task,@@ -65,9 +65,10 @@ export function dataSourceSlug(dataSource: DataSource): string {}export function migrationHistorySlug(- migrationHistory: MigrationHistory+ migrationHistoryId: MigrationHistoryId,+ version: string): string {- return [slug(migrationHistory.version), migrationHistory.id].join("-");+ return [slug(version), migrationHistoryId].join("-");}export function fullDatabasePath(database: Database): string {diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sqlindex ede24c89e6..7cb834e9d6 100644--- a/store/migration/10001__init_schema.sql+++ b/store/migration/10001__init_schema.sql@@ -843,6 +843,8 @@ CREATE TABLE task_run (`type` TEXT NOT NULL CHECK (`type` LIKE 'bb.task.%'),code INTEGER NOT NULL DEFAULT 0,comment TEXT NOT NULL DEFAULT '',+ -- result saves the task run result in json format+ result TEXT NOT NULL DEFAULT '',payload TEXT NOT NULL DEFAULT '');diff --git a/store/seed/release/10001__init_seed.sql b/store/seed/release/10001__init_seed.sqlindex 64f064ef13..a870076e65 100644--- a/store/seed/release/10001__init_seed.sql+++ b/store/seed/release/10001__init_seed.sql@@ -372,6 +372,7 @@ INSERT INTO`status`,`type`,comment,+ result,payload)VALUES@@ -382,7 +383,8 @@ VALUES'Welcome','FAILED','bb.task.general',- 'Something is not right...',+ '',+ '{"detail":"Something is not right..."}','');diff --git a/store/seed/test/10120__task_run.sql b/store/seed/test/10120__task_run.sqlindex 958a633700..88ede687d2 100644--- a/store/seed/test/10120__task_run.sql+++ b/store/seed/test/10120__task_run.sql@@ -10,7 +10,7 @@ INSERT INTO`status`,`type`,code,- comment,+ result,payload)VALUES@@ -24,7 +24,7 @@ VALUES'DONE','bb.task.database.schema.update',0,- 'Established baseline version 202106280000 for database ''shop''',+ '{"detail":"Established baseline version 202106280000 for database ''shop''","migrationId":1,"version":"202106280000"}','{"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"}}}');@@ -40,7 +40,7 @@ INSERT INTO`status`,`type`,code,- comment,+ result,payload)VALUES@@ -54,7 +54,7 @@ VALUES'DONE','bb.task.database.schema.update',0,- 'Established baseline version 202106280000 for database ''shop''',+ '{"detail":"Established baseline version 202106280000 for database ''shop''","migrationId":1,"version":"202106280000"}','{"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"}}}');@@ -69,7 +69,7 @@ INSERT INTO`status`,`type`,code,- comment+ result)VALUES(@@ -81,7 +81,7 @@ VALUES'FAILED','bb.task.database.schema.update',103,- 'table "tbl1" already exists'+ '{"detail":"table \"tbl1\" already exists"}');-- Task run for task 11008@@ -96,7 +96,7 @@ INSERT INTO`status`,`type`,code,- comment,+ result,payload)VALUES@@ -110,7 +110,7 @@ VALUES'DONE','bb.task.database.schema.update',0,- 'Established baseline version 202106280000 for database ''blog''',+ '{"detail":"Established baseline version 202106280000 for database ''blog''","migrationId":1,"version":"202106280000"}','{"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"}}}');@@ -126,7 +126,7 @@ INSERT INTO`status`,`type`,code,- comment,+ result,payload)VALUES@@ -140,7 +140,7 @@ VALUES'DONE','bb.task.database.schema.update',0,- 'Established baseline version 202106280000 for database ''blog''',+ '{"detail":"Established baseline version 202106280000 for database ''blog''","migrationId":1,"version":"202106280000"}','{"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"}}}');@@ -156,7 +156,7 @@ INSERT INTO`status`,`type`,code,- comment,+ result,payload)VALUES@@ -170,7 +170,7 @@ VALUES'DONE','bb.task.database.schema.update',0,- 'Established baseline version 202106280000 for database ''blog''',+ '{"detail":"Established baseline version 202106280000 for database ''blog''","migrationId":1,"version":"202106280000"}','{"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"}}}');@@ -186,7 +186,7 @@ INSERT INTO`status`,`type`,code,- comment,+ result,payload)VALUES@@ -200,7 +200,7 @@ VALUES'DONE','bb.task.database.schema.update',0,- 'Established baseline version 202106280000 for database ''blog''',+ '{"detail":"Established baseline version 202106280000 for database ''blog''","migrationId":1,"version":"202106280000"}','{"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"}}}');@@ -216,7 +216,7 @@ INSERT INTO`status`,`type`,code,- comment,+ result,payload)VALUES@@ -230,7 +230,7 @@ VALUES'FAILED','bb.task.database.schema.update',201,- 'database ''blog'' has already applied version 202106280100',+ '{"detail":"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"}}}');@@ -246,7 +246,7 @@ INSERT INTO`status`,`type`,code,- comment,+ result,payload)VALUES@@ -260,7 +260,7 @@ VALUES'DONE','bb.task.database.schema.update',0,- 'Applied migration version 20210830011437.11013 to database "testdb_dev"',+ '{"detail":"Applied migration version 20210830011437.11013 to database \"testdb_dev\"","migrationId":1,"version":"20210830011437.11013"}','{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_dev.tbl2 (name TEXT)"}');@@ -275,7 +275,7 @@ INSERT INTOname,`status`,`type`,- comment,+ result,payload)VALUES@@ -288,7 +288,7 @@ VALUES'Update testdb_integration task run','DONE','bb.task.database.schema.update',- 'Applied migration version 20210830011437.11014 to database "testdb_integration"',+ '{"detail":"Applied migration version 20210830011437.11014 to database \"testdb_integration\"","migrationId":1,"version":"20210830011437.11014"}','{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_integration.tbl2 (name TEXT)"}');@@ -304,7 +304,7 @@ INSERT INTO`status`,`type`,code,- comment,+ result,payload)VALUES@@ -318,6 +318,6 @@ VALUES'FAILED','bb.task.database.schema.update',103,- 'table "tbl2" already exists',+ '{"detail":"table \"tbl2\" already exists"}','{"migrationType":"MIGRATE","statement":"CREATE TABLE testdb_staging.tbl2 (name TEXT)"}');\ No newline at end of filediff --git a/store/task.go b/store/task.goindex b6f380baa2..b564c1664e 100644--- a/store/task.go+++ b/store/task.go@@ -420,6 +420,7 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.TaUpdaterId: patch.UpdaterId,TaskId: &patch.ID,Code: patch.Code,+ Result: patch.Result,Comment: patch.Comment,}switch patch.Status {diff --git a/store/task_run.go b/store/task_run.goindex 6d3d6ae115..4f574a5113 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, createpayload)VALUES (?, ?, ?, ?, 'RUNNING', ?, ?)- RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, `+"`status`, `type`, code, comment, payload"+`+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, `+"`status`, `type`, code, comment, result, payload"+``,create.CreatorId,create.CreatorId,@@ -68,6 +68,7 @@ func (s *TaskRunService) CreateTaskRunTx(ctx context.Context, tx *sql.Tx, create&taskRun.Type,&taskRun.Code,&taskRun.Comment,+ &taskRun.Result,&taskRun.Payload,); err != nil {return nil, FormatError(err)@@ -112,6 +113,9 @@ func (s *TaskRunService) PatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, pif v := patch.Comment; v != nil {set, args = append(set, "comment = ?"), append(args, *v)}+ if v := patch.Result; v != nil {+ set, args = append(set, "result = ?"), append(args, *v)+ }// Build WHERE clause.where := []string{"1 = 1"}@@ -126,7 +130,7 @@ func (s *TaskRunService) PatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, pUPDATE task_runSET `+strings.Join(set, ", ")+`WHERE `+strings.Join(where, " AND ")+`- RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, `+"`status`, `type`, code, comment, payload"+`+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, `+"`status`, `type`, code, comment, result, payload"+``,args...,)@@ -150,6 +154,7 @@ func (s *TaskRunService) PatchTaskRunStatusTx(ctx context.Context, tx *sql.Tx, p&taskRun.Type,&taskRun.Code,&taskRun.Comment,+ &taskRun.Result,&taskRun.Payload,); err != nil {return nil, FormatError(err)@@ -190,6 +195,7 @@ func (s *TaskRunService) findTaskRunList(ctx context.Context, tx *sql.Tx, find *`+"`type`,"+`code,comment,+ result,payloadFROM task_runWHERE `+strings.Join(where, " AND "),@@ -216,6 +222,7 @@ func (s *TaskRunService) findTaskRunList(ctx context.Context, tx *sql.Tx, find *&taskRun.Type,&taskRun.Code,&taskRun.Comment,+ &taskRun.Result,&taskRun.Payload,); err != nil {return nil, FormatError(err)