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 TaskRun model and return it to the client
天舟6dcb85f37369
diff --git a/backend/api/task_run.go b/backend/api/task_run.goindex 35c67b10f6..42df838b95 100644--- a/backend/api/task_run.go+++ b/backend/api/task_run.go@@ -30,7 +30,7 @@ func (e TaskRunStatus) String() string {}type TaskRun struct {- ID int+ ID int `jsonapi:"primary,taskRun"`// Standard fieldsCreatorId intdiff --git a/backend/store/migration/0001_init_schema.up.sql b/backend/store/migration/0001_init_schema.up.sqlindex 5813cb8c26..d2c2ecae30 100644--- a/backend/store/migration/0001_init_schema.up.sql+++ b/backend/store/migration/0001_init_schema.up.sql@@ -501,8 +501,11 @@ END;-- task run table stores the task runCREATE TABLE task_run (id INTEGER PRIMARY KEY AUTOINCREMENT,+ creator_id INTEGER NOT NULL REFERENCES principal (id),created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),+ updater_id INTEGER NOT NULL REFERENCES principal (id),updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),+ workspace_id INTEGER NOT NULL REFERENCES workspace (id),task_id INTEGER NOT NULL REFERENCES task (id),name TEXT NOT NULL,`status` TEXT NOT NULL CHECK (diff --git a/backend/store/seed/0090_pipeline.sql b/backend/store/seed/0090_pipeline.sqlindex 3046a6b753..4d06aba5fc 100644--- a/backend/store/seed/0090_pipeline.sql+++ b/backend/store/seed/0090_pipeline.sql@@ -1,4 +1,4 @@--- A single stage, single step "hello world" pipeline+-- A single stage, single task "hello world"INSERT INTOpipeline (id,@@ -18,7 +18,7 @@ VALUES'OPEN');--- A multi stage, each containing a single step schema update pipeline+-- A multi stage, each containing a single add column taskINSERT INTOpipeline (id,@@ -36,4 +36,24 @@ VALUES1,'Pipeline - Add column ''location'' to table ''warehouse''','OPEN'+ );++-- A two stage, each containing a single create table task, the 1st task has a failed task run+INSERT INTO+ pipeline (+ id,+ creator_id,+ updater_id,+ workspace_id,+ name,+ `status`+ )+VALUES+ (+ 9003,+ 1003,+ 1003,+ 1,+ 'Pipeline - Create table ''tbl1''',+ 'OPEN');\ No newline at end of filediff --git a/backend/store/seed/0100_stage.sql b/backend/store/seed/0100_stage.sqlindex 25cbd9049d..a00968f425 100644--- a/backend/store/seed/0100_stage.sql+++ b/backend/store/seed/0100_stage.sql@@ -22,7 +22,7 @@ VALUES'bb.stage.schema.update');--- Stage for Pipeline 9002 schema update+-- Stage for Pipeline 9002 add columnINSERT INTOstage (id,@@ -37,8 +37,8 @@ INSERT INTOVALUES(10002,- 1001,- 1001,+ 1003,+ 1003,1,9002,5001,@@ -60,8 +60,8 @@ INSERT INTOVALUES(10003,- 1001,- 1001,+ 1003,+ 1003,1,9002,5002,@@ -83,8 +83,8 @@ INSERT INTOVALUES(10004,- 1001,- 1001,+ 1003,+ 1003,1,9002,5003,@@ -106,11 +106,58 @@ INSERT INTOVALUES(10005,- 1001,- 1001,+ 1003,+ 1003,1,9002,5004,'Prod','bb.stage.schema.update'+ );++-- Stage for Pipeline 9003 create table+INSERT INTO+ stage (+ id,+ creator_id,+ updater_id,+ workspace_id,+ pipeline_id,+ environment_id,+ name,+ `type`+ )+VALUES+ (+ 10006,+ 1003,+ 1003,+ 1,+ 9003,+ 5001,+ 'Sandbox A',+ 'bb.stage.schema.update'+ );++INSERT INTO+ stage (+ id,+ creator_id,+ updater_id,+ workspace_id,+ pipeline_id,+ environment_id,+ name,+ `type`+ )+VALUES+ (+ 10007,+ 1003,+ 1003,+ 1,+ 9003,+ 5002,+ 'Integration',+ 'bb.stage.schema.update');\ No newline at end of filediff --git a/backend/store/seed/0110_task.sql b/backend/store/seed/0110_task.sqlindex 27c61992d2..17db8335d8 100644--- a/backend/store/seed/0110_task.sql+++ b/backend/store/seed/0110_task.sql@@ -28,8 +28,8 @@ VALUES'MANUAL');--- Task for Pipeline 9002 schema update--- Taks for stage 10002 "Sandbox A" to update database 7002 'fakedb1'+-- Task for Pipeline 9002 add column+-- Task for stage 10002 "Sandbox A" to update database 7002 'fakedb1'INSERT INTOtask (id,@@ -47,8 +47,8 @@ INSERT INTOVALUES(11002,- 1001,- 1001,+ 1003,+ 1003,1,9002,10002,@@ -59,7 +59,7 @@ VALUES'ON_SUCCESS');--- Taks for stage 10003 "Integration" to update database 7004 'fakedb2'+-- Task for stage 10003 "Integration" to update database 7004 'fakedb2'INSERT INTOtask (id,@@ -77,8 +77,8 @@ INSERT INTOVALUES(11003,- 1001,- 1001,+ 1003,+ 1003,1,9002,10003,@@ -89,7 +89,7 @@ VALUES'ON_SUCCESS');--- Taks for stage 10004 "Staging" to update database 7006 'fakedb3'+-- Task for stage 10004 "Staging" to update database 7006 'fakedb3'INSERT INTOtask (id,@@ -107,8 +107,8 @@ INSERT INTOVALUES(11004,- 1001,- 1001,+ 1003,+ 1003,1,9002,10004,@@ -119,7 +119,7 @@ VALUES'MANUAL');--- Taks for stage 10005 "Prod" to update database 7008 'fakedb4'+-- Task for stage 10005 "Prod" to update database 7008 'fakedb4'INSERT INTOtask (id,@@ -137,8 +137,8 @@ INSERT INTOVALUES(11005,- 1001,- 1001,+ 1003,+ 1003,1,9002,10005,@@ -147,4 +147,65 @@ VALUES'bb.task.database.schema.update','PENDING','MANUAL'+ );++-- Task for Pipeline 9003 create table+-- Task for stage 10006 "Sandbox A" to craete table in database 7002 'fakedb1'+INSERT INTO+ task (+ id,+ creator_id,+ updater_id,+ workspace_id,+ pipeline_id,+ stage_id,+ database_id,+ name,+ `type`,+ `status`,+ `when`+ )+VALUES+ (+ 11006,+ 1003,+ 1003,+ 1,+ 9003,+ 10006,+ 7002,+ 'Update fakedb1',+ 'bb.task.database.schema.update',+ 'PENDING',+ 'ON_SUCCESS'+ );++-- Task for stage 10003 "Integration" to update database 7004 'fakedb2'+INSERT INTO+ task (+ id,+ creator_id,+ updater_id,+ workspace_id,+ pipeline_id,+ stage_id,+ database_id,+ name,+ `type`,+ `status`,+ `when`+ )+VALUES+ (+ 11007,+ 1003,+ 1003,+ 1,+ 9003,+ 10007,+ 7004,+ 'Update fakedb2',+ 'bb.task.database.schema.update',+ 'PENDING',+ 'ON_SUCCESS');\ No newline at end of filediff --git a/backend/store/seed/0120_task_run.sql b/backend/store/seed/0120_task_run.sqlnew file mode 100644index 0000000000..db01631acc--- /dev/null+++ b/backend/store/seed/0120_task_run.sql@@ -0,0 +1,23 @@+-- Failed task run for task 11006 create table+INSERT INTO+ task_run (+ id,+ creator_id,+ updater_id,+ workspace_id,+ task_id,+ name,+ `status`,+ `type`+ )+VALUES+ (+ 12001,+ 1003,+ 1003,+ 1,+ 11006,+ 'UPDATE fakedb1 task run',+ 'FAILED',+ 'bb.task.database.schema.update'+ );\ No newline at end of filediff --git a/backend/store/seed/0120_issue.sql b/backend/store/seed/0130_issue.sqlsimilarity index 72%rename from backend/store/seed/0120_issue.sqlrename to backend/store/seed/0130_issue.sqlindex 94704248fd..52a4857073 100644--- a/backend/store/seed/0120_issue.sql+++ b/backend/store/seed/0130_issue.sql@@ -18,7 +18,7 @@ INSERT INTO)VALUES(- 12001,+ 13001,1002,1002,1,@@ -34,7 +34,7 @@ VALUES'');--- Issue for the multi stage update schema pipeline+-- Issue for the multi stage add column pipelineINSERT INTOissue (id,@@ -54,7 +54,7 @@ INSERT INTO)VALUES(- 12002,+ 13002,1003,1003,1,@@ -68,4 +68,40 @@ VALUES'1001,1002,1003,1004','ALTER TABLE warehouse ' || char(10) || 'ADD COLUMN location VARCHAR(255);','ALTER TABLE warehouse ' || char(10) || 'DROP COLUMN location;'+ );++-- Issue for the multi stage create table pipeline+INSERT INTO+ issue (+ id,+ creator_id,+ updater_id,+ workspace_id,+ project_id,+ pipeline_id,+ name,+ `status`,+ `type`,+ description,+ assignee_id,+ subscriber_id_list,+ `sql`,+ rollback_sql+ )+VALUES+ (+ 13003,+ 1003,+ 1003,+ 1,+ 3002,+ 9003,+ 'Create a new table ''tbl1''',+ 'OPEN',+ 'bb.issue.db.schema.update',+ 'Create tbl1.',+ 1001,+ '1001,1002,1003,1004',+ 'CREATE TABLE tbl1;',+ 'DROP TABLE tbl1;');\ No newline at end of filediff --git a/backend/store/seed/0130_activity.sql b/backend/store/seed/0140_activity.sqlsimilarity index 89%rename from backend/store/seed/0130_activity.sqlrename to backend/store/seed/0140_activity.sqlindex 37874a0fd1..a9575e09c2 100644--- a/backend/store/seed/0130_activity.sql+++ b/backend/store/seed/0140_activity.sql@@ -1,4 +1,4 @@--- Activity for issue 012001+-- Activity for issue 013001INSERT INTOactivity (id,@@ -10,11 +10,11 @@ INSERT INTO)VALUES(- 13001,+ 14001,1,1,1,- 12001,+ 13001,'bb.issue.create');@@ -30,11 +30,11 @@ INSERT INTO)VALUES(- 13002,+ 14002,1001,1001,1,- 12001,+ 13001,'bb.issue.comment.create','Welcome!');@@ -51,11 +51,11 @@ INSERT INTO)VALUES(- 13003,+ 14003,1002,1002,1,- 12001,+ 13001,'bb.issue.comment.create','Let''s rock!');@@ -72,11 +72,11 @@ INSERT INTO)VALUES(- 13004,+ 14004,1003,1003,1,- 12001,+ 13001,'bb.issue.comment.create','Go fish!');@@ -93,10 +93,10 @@ INSERT INTO)VALUES(- 13005,+ 14005,1,1,1,- 12002,+ 13002,'bb.issue.create');\ No newline at end of filediff --git a/backend/store/seed/0140_bookmark.sql b/backend/store/seed/0150_bookmark.sqlsimilarity index 100%rename from backend/store/seed/0140_bookmark.sqlrename to backend/store/seed/0150_bookmark.sqldiff --git a/backend/store/task_run.go b/backend/store/task_run.goindex f99038521b..6f3d95080b 100644--- a/backend/store/task_run.go+++ b/backend/store/task_run.go@@ -92,7 +92,7 @@ func createTaskRun(ctx context.Context, tx *Tx, create *api.TaskRunCreate) (*apipayload)VALUES (?, ?, 'PENDING', ?, ?)- RETURNING id, created_ts, updated_ts, task_id, name, `+"`status`, `type`, payload"+`+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, task_id, name, `+"`status`, `type`, payload"+``,create.TaskId,create.Name,@@ -109,7 +109,9 @@ func createTaskRun(ctx context.Context, tx *Tx, create *api.TaskRunCreate) (*apivar taskRun api.TaskRunif err := row.Scan(&taskRun.ID,+ &taskRun.CreatorId,&taskRun.CreatedTs,+ &taskRun.UpdaterId,&taskRun.UpdatedTs,&taskRun.TaskId,&taskRun.Name,@@ -136,7 +138,9 @@ func findTaskRunList(ctx context.Context, tx *Tx, find *api.TaskRunFind) (_ []*arows, err := tx.QueryContext(ctx, `SELECTid,+ creator_id,created_ts,+ updater_id,updated_ts,task_id,name,@@ -158,7 +162,9 @@ func findTaskRunList(ctx context.Context, tx *Tx, find *api.TaskRunFind) (_ []*avar taskRun api.TaskRunif err := rows.Scan(&taskRun.ID,+ &taskRun.CreatorId,&taskRun.CreatedTs,+ &taskRun.UpdaterId,&taskRun.UpdatedTs,&taskRun.TaskId,&taskRun.Name,diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.tsindex a0a049ea0b..cbb8ec4540 100644--- a/frontend/src/store/modules/task.ts+++ b/frontend/src/store/modules/task.ts@@ -15,10 +15,27 @@ import {empty,ResourceIdentifier,Principal,+ TaskRun,} from "../../types";const state: () => TaskState = () => ({});+function convertTaskRun(+ taskRun: ResourceObject,+ includedList: ResourceObject[],+ rootGetters: any+): TaskRun {+ const creator = taskRun.attributes.creator as Principal;+ const updater = taskRun.attributes.updater as Principal;++ return {+ ...(taskRun.attributes as Omit<TaskRun, "id" | "creator" | "updater">),+ id: parseInt(taskRun.id),+ creator,+ updater,+ };+}+function convertPartial(task: ResourceObject,includedList: ResourceObject[],@@ -27,6 +44,27 @@ function convertPartial(const creator = task.attributes.creator as Principal;const updater = task.attributes.updater as Principal;+ const taskRunList: TaskRun[] = [];+ const taskRunIdList = task.relationships!.taskRun+ .data as ResourceIdentifier[];+ // Needs to iterate through taskIdList to maintain the order+ for (const idItem of taskRunIdList) {+ for (const item of includedList || []) {+ if (item.type == "taskRun") {+ if (idItem.id == item.id) {+ const taskRun: TaskRun = convertTaskRun(+ item,+ includedList,+ rootGetters+ );+ taskRunList.push(taskRun);+ }+ }+ }+ }++ console.log("taskRunList11", taskRunList);+const databaseId = (task.relationships!.database.data as ResourceIdentifier).id;let database: Database = empty("DATABASE") as Database;@@ -43,12 +81,19 @@ function convertPartial(return {...(task.attributes as Omit<Task,- "id" | "creator" | "updater" | "database" | "pipeline" | "stage"+ | "id"+ | "creator"+ | "updater"+ | "database"+ | "taskRunList"+ | "pipeline"+ | "stage">),id: parseInt(task.id),creator,updater,database,+ taskRunList,};}diff --git a/frontend/src/types/id.ts b/frontend/src/types/id.tsindex 020127a68f..fa152a624a 100644--- a/frontend/src/types/id.ts+++ b/frontend/src/types/id.ts@@ -21,6 +21,8 @@ export type StageId = IdType;export type TaskId = IdType;+export type TaskRunId = IdType;+export type ActivityId = IdType;export type MessageId = IdType;diff --git a/frontend/src/types/pipeline.ts b/frontend/src/types/pipeline.tsindex a94a0714ce..b498607f7a 100644--- a/frontend/src/types/pipeline.ts+++ b/frontend/src/types/pipeline.ts@@ -78,6 +78,7 @@ import {PrincipalId,StageId,TaskId,+ TaskRunId,} from "./id";import { Principal } from "./principal";@@ -208,6 +209,7 @@ export type Task = {id: TaskId;// Related fields+ taskRunList: TaskRun[];pipeline: Pipeline;stage: Stage;@@ -245,3 +247,27 @@ export type TaskStatusPatch = {status: TaskStatus;comment?: string;};++// TaskRun is one run of a particular task+export type TaskRunStatus =+ | "PENDING"+ | "RUNNING"+ | "DONE"+ | "FAILED"+ | "CANCELED";++export type TaskRun = {+ id: TaskRunId;++ // Standard fields+ creator: Principal;+ createdTs: number;+ updater: Principal;+ updatedTs: number;++ // Domain specific fields+ name: string;+ status: TaskRunStatus;+ type: TaskType;+ payload?: TaskPayload;+};