Skip to content

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

Add TaskRun model and return it to the client

天舟6dcb85f37369
diff --git a/backend/api/task_run.go b/backend/api/task_run.go
index 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 fields
CreatorId int
diff --git a/backend/store/migration/0001_init_schema.up.sql b/backend/store/migration/0001_init_schema.up.sql
index 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 run
CREATE 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.sql
index 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 INTO
pipeline (
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 task
INSERT INTO
pipeline (
id,
@@ -36,4 +36,24 @@ VALUES
1,
'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 file
diff --git a/backend/store/seed/0100_stage.sql b/backend/store/seed/0100_stage.sql
index 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 column
INSERT INTO
stage (
id,
@@ -37,8 +37,8 @@ INSERT INTO
VALUES
(
10002,
- 1001,
- 1001,
+ 1003,
+ 1003,
1,
9002,
5001,
@@ -60,8 +60,8 @@ INSERT INTO
VALUES
(
10003,
- 1001,
- 1001,
+ 1003,
+ 1003,
1,
9002,
5002,
@@ -83,8 +83,8 @@ INSERT INTO
VALUES
(
10004,
- 1001,
- 1001,
+ 1003,
+ 1003,
1,
9002,
5003,
@@ -106,11 +106,58 @@ INSERT INTO
VALUES
(
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 file
diff --git a/backend/store/seed/0110_task.sql b/backend/store/seed/0110_task.sql
index 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 INTO
task (
id,
@@ -47,8 +47,8 @@ INSERT INTO
VALUES
(
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 INTO
task (
id,
@@ -77,8 +77,8 @@ INSERT INTO
VALUES
(
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 INTO
task (
id,
@@ -107,8 +107,8 @@ INSERT INTO
VALUES
(
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 INTO
task (
id,
@@ -137,8 +137,8 @@ INSERT INTO
VALUES
(
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 file
diff --git a/backend/store/seed/0120_task_run.sql b/backend/store/seed/0120_task_run.sql
new file mode 100644
index 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 file
diff --git a/backend/store/seed/0120_issue.sql b/backend/store/seed/0130_issue.sql
similarity index 72%
rename from backend/store/seed/0120_issue.sql
rename to backend/store/seed/0130_issue.sql
index 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 pipeline
INSERT INTO
issue (
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 file
diff --git a/backend/store/seed/0130_activity.sql b/backend/store/seed/0140_activity.sql
similarity index 89%
rename from backend/store/seed/0130_activity.sql
rename to backend/store/seed/0140_activity.sql
index 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 013001
INSERT INTO
activity (
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 file
diff --git a/backend/store/seed/0140_bookmark.sql b/backend/store/seed/0150_bookmark.sql
similarity index 100%
rename from backend/store/seed/0140_bookmark.sql
rename to backend/store/seed/0150_bookmark.sql
diff --git a/backend/store/task_run.go b/backend/store/task_run.go
index 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) (*api
payload
)
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) (*api
var taskRun api.TaskRun
if 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) (_ []*a
rows, err := tx.QueryContext(ctx, `
SELECT
id,
+ 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) (_ []*a
var taskRun api.TaskRun
if 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.ts
index 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.ts
index 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.ts
index 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;
+};