Skip to content

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

Use PENDING_APPROVAL to denote task requiring approval

天舟858703901ba1
diff --git a/backend/api/task.go b/backend/api/task.go
index 9ae07bb7dd..440ed04240 100644
--- a/backend/api/task.go
+++ b/backend/api/task.go
@@ -8,18 +8,21 @@ import (
type TaskStatus string
const (
- TaskPending TaskStatus = "PENDING"
- TaskRunning TaskStatus = "RUNNING"
- TaskDone TaskStatus = "DONE"
- TaskFailed TaskStatus = "FAILED"
- TaskCanceled TaskStatus = "CANCELED"
- TaskSkipped TaskStatus = "SKIPPED"
+ TaskPending TaskStatus = "PENDING"
+ TaskPendingApproval TaskStatus = "PENDING_APPROVAL"
+ TaskRunning TaskStatus = "RUNNING"
+ TaskDone TaskStatus = "DONE"
+ TaskFailed TaskStatus = "FAILED"
+ TaskCanceled TaskStatus = "CANCELED"
+ TaskSkipped TaskStatus = "SKIPPED"
)
func (e TaskStatus) String() string {
switch e {
case TaskPending:
return "PENDING"
+ case TaskPendingApproval:
+ return "PENDING_APPROVAL"
case TaskRunning:
return "RUNNING"
case TaskDone:
@@ -45,13 +48,6 @@ const (
TaskDatabaseSchemaUpdate TaskType = "bb.task.database.schema.update"
)
-type TaskWhen string
-
-const (
- TaskOnSuccess TaskWhen = "ON_SUCCESS"
- TaskManual TaskWhen = "MANUAL"
-)
-
type TaskDatabaseSchemaUpdatePayload struct {
Sql string
RollbackSql string
@@ -81,7 +77,6 @@ type Task struct {
Name string `jsonapi:"attr,name"`
Status TaskStatus `jsonapi:"attr,status"`
Type TaskType `jsonapi:"attr,type"`
- When TaskWhen `jsonapi:"attr,when"`
Payload []byte `jsonapi:"attr,payload"`
}
@@ -97,10 +92,10 @@ type TaskCreate struct {
DatabaseId int `jsonapi:"attr,databaseId"`
// Domain specific fields
- Name string `jsonapi:"attr,name"`
- Type TaskType `jsonapi:"attr,type"`
- When TaskWhen `jsonapi:"attr,when"`
- Payload []byte `jsonapi:"attr,payload"`
+ Name string `jsonapi:"attr,name"`
+ Status TaskStatus `jsonapi:"attr,status"`
+ Type TaskType `jsonapi:"attr,type"`
+ Payload []byte `jsonapi:"attr,payload"`
}
type TaskFind struct {
diff --git a/backend/server/pipeline.go b/backend/server/pipeline.go
index d80962c7a4..4434e135fb 100644
--- a/backend/server/pipeline.go
+++ b/backend/server/pipeline.go
@@ -47,12 +47,10 @@ func (s *Server) ComposePipelineRelationship(ctx context.Context, pipeline *api.
func (s *Server) ScheduleNextTaskIfNeeded(ctx context.Context, pipeline *api.Pipeline) error {
for _, stage := range pipeline.StageList {
for _, task := range stage.TaskList {
- if !task.Status.IsEndStatus() {
- if task.When == api.TaskOnSuccess {
- _, err := s.TaskScheduler.Schedule(context.Background(), *task, api.SYSTEM_BOT_ID)
- if err != nil {
- return err
- }
+ if task.Status == api.TaskPending {
+ _, err := s.TaskScheduler.Schedule(context.Background(), *task, api.SYSTEM_BOT_ID)
+ if err != nil {
+ return err
}
return nil
}
diff --git a/backend/server/task.go b/backend/server/task.go
index 8cbfa47306..52a210a347 100644
--- a/backend/server/task.go
+++ b/backend/server/task.go
@@ -61,11 +61,7 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch task ID: %v", taskId)).SetInternal(err)
}
- if task.When != api.TaskManual {
- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Task does not require approval: %v", task.Name))
- }
-
- if task.Status != api.TaskPending {
+ if task.Status != api.TaskPendingApproval {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Task is not waiting for approval: %v", task.Name))
}
diff --git a/backend/store/migration/0001_init_schema.up.sql b/backend/store/migration/0001_init_schema.up.sql
index 9dd9204eaa..cea88a5132 100644
--- a/backend/store/migration/0001_init_schema.up.sql
+++ b/backend/store/migration/0001_init_schema.up.sql
@@ -469,6 +469,7 @@ CREATE TABLE task (
`status` TEXT NOT NULL CHECK (
`status` IN (
'PENDING',
+ 'PENDING_APPROVAL',
'RUNNING',
'DONE',
'FAILED',
@@ -477,7 +478,6 @@ CREATE TABLE task (
)
),
`type` TEXT NOT NULL CHECK (`type` LIKE 'bb.task.%'),
- `when` TEXT NOT NULL CHECK (`when` IN ('ON_SUCCESS', 'MANUAL')),
payload TEXT NOT NULL DEFAULT ''
);
diff --git a/backend/store/seed/0110_task.sql b/backend/store/seed/0110_task.sql
index b0c6d1d303..2c7e6c0d60 100644
--- a/backend/store/seed/0110_task.sql
+++ b/backend/store/seed/0110_task.sql
@@ -11,7 +11,6 @@ INSERT INTO
name,
`type`,
`status`,
- `when`,
payload
)
VALUES
@@ -25,8 +24,7 @@ VALUES
7008,
'Welcome',
'bb.task.general',
- 'PENDING',
- 'MANUAL',
+ 'PENDING_APPROVAL',
'{"Sql":"SELECT ''Welcome Tech Lead, DBA, Developer'';"}'
);
@@ -43,8 +41,7 @@ INSERT INTO
database_id,
name,
`type`,
- `status`,
- `when`
+ `status`
)
VALUES
(
@@ -57,8 +54,7 @@ VALUES
7002,
'Update fakedb1',
'bb.task.database.schema.update',
- 'PENDING',
- 'ON_SUCCESS'
+ 'PENDING'
);
-- Task for stage 10003 "Integration" to update database 7004 'fakedb2'
@@ -73,8 +69,7 @@ INSERT INTO
database_id,
name,
`type`,
- `status`,
- `when`
+ `status`
)
VALUES
(
@@ -87,8 +82,7 @@ VALUES
7004,
'Update fakedb2',
'bb.task.database.schema.update',
- 'PENDING',
- 'ON_SUCCESS'
+ 'PENDING'
);
-- Task for stage 10004 "Staging" to update database 7006 'fakedb3'
@@ -103,8 +97,7 @@ INSERT INTO
database_id,
name,
`type`,
- `status`,
- `when`
+ `status`
)
VALUES
(
@@ -117,8 +110,7 @@ VALUES
7006,
'Update fakedb3',
'bb.task.database.schema.update',
- 'PENDING',
- 'MANUAL'
+ 'PENDING_APPROVAL'
);
-- Task for stage 10005 "Prod" to update database 7008 'fakedb4'
@@ -133,8 +125,7 @@ INSERT INTO
database_id,
name,
`type`,
- `status`,
- `when`
+ `status`
)
VALUES
(
@@ -147,8 +138,7 @@ VALUES
7008,
'Update fakedb4',
'bb.task.database.schema.update',
- 'PENDING',
- 'MANUAL'
+ 'PENDING_APPROVAL'
);
-- Task for Pipeline 9003 create table
@@ -164,8 +154,7 @@ INSERT INTO
database_id,
name,
`type`,
- `status`,
- `when`
+ `status`
)
VALUES
(
@@ -178,8 +167,7 @@ VALUES
7002,
'Update fakedb1',
'bb.task.database.schema.update',
- 'PENDING',
- 'MANUAL'
+ 'PENDING_APPROVAL'
);
-- Task for stage 10003 "Integration" to update database 7004 'fakedb2'
@@ -194,8 +182,7 @@ INSERT INTO
database_id,
name,
`type`,
- `status`,
- `when`
+ `status`
)
VALUES
(
@@ -208,6 +195,5 @@ VALUES
7004,
'Update fakedb2',
'bb.task.database.schema.update',
- 'PENDING',
- 'ON_SUCCESS'
+ 'PENDING'
);
\ No newline at end of file
diff --git a/backend/store/task.go b/backend/store/task.go
index 4f3a12f419..27e3465a1d 100644
--- a/backend/store/task.go
+++ b/backend/store/task.go
@@ -116,11 +116,10 @@ func (s *TaskService) createTask(ctx context.Context, tx *Tx, create *api.TaskCr
name,
`+"`status`,"+`
`+"`type`,"+`
- `+"`when`,"+`
payload
)
- VALUES (?, ?, ?, ?, ?, ?, ?, 'PENDING', ?, ?, ?)
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, workspace_id, pipeline_id, stage_id, database_id, name, `+"`status`, `type`, `when`, payload"+`
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, workspace_id, pipeline_id, stage_id, database_id, name, `+"`status`, `type`, payload"+`
`,
create.CreatorId,
create.CreatorId,
@@ -129,8 +128,8 @@ func (s *TaskService) createTask(ctx context.Context, tx *Tx, create *api.TaskCr
create.StageId,
create.DatabaseId,
create.Name,
+ create.Status,
create.Type,
- create.When,
create.Payload,
)
@@ -154,7 +153,6 @@ func (s *TaskService) createTask(ctx context.Context, tx *Tx, create *api.TaskCr
&task.Name,
&task.Status,
&task.Type,
- &task.When,
&task.Payload,
); err != nil {
return nil, FormatError(err)
@@ -193,7 +191,6 @@ func (s *TaskService) findTaskList(ctx context.Context, tx *Tx, find *api.TaskFi
name,
`+"`status`,"+`
`+"`type`,"+`
- `+"`when`,"+`
payload
FROM task
WHERE `+strings.Join(where, " AND "),
@@ -221,7 +218,6 @@ func (s *TaskService) findTaskList(ctx context.Context, tx *Tx, find *api.TaskFi
&task.Name,
&task.Status,
&task.Type,
- &task.When,
&task.Payload,
); err != nil {
return nil, FormatError(err)
@@ -263,7 +259,7 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.Ta
UPDATE task
SET `+strings.Join(set, ", ")+`
WHERE id = ?
- RETURNING id, creator_id, created_ts, updater_id, updated_ts, workspace_id, pipeline_id, stage_id, database_id, name, `+"`status`, `type`, `when`, payload"+`
+ RETURNING id, creator_id, created_ts, updater_id, updated_ts, workspace_id, pipeline_id, stage_id, database_id, name, `+"`status`, `type`, payload"+`
`,
args...,
)
@@ -287,7 +283,6 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.Ta
&task.Name,
&task.Status,
&task.Type,
- &task.When,
&task.Payload,
); err != nil {
return nil, FormatError(err)
diff --git a/frontend/src/bbkit/BBStepBar.vue b/frontend/src/bbkit/BBStepBar.vue
index 85d0365f6f..c183c0d250 100644
--- a/frontend/src/bbkit/BBStepBar.vue
+++ b/frontend/src/bbkit/BBStepBar.vue
@@ -26,6 +26,27 @@
aria-hidden="true"
></span>
</template>
+ <template
+ v-else-if="
+ step.status == `PENDING_APPROVAL` ||
+ step.status == `PENDING_APPROVAL_ACTIVE`
+ "
+ >
+ <svg
+ class="w-4 h-4"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"
+ ></path>
+ </svg>
+ </template>
<template v-else-if="step.status == `RUNNING`">
<span
class="h-2.5 w-2.5 bg-blue-600 rounded-full"
@@ -52,7 +73,15 @@
</template>
<template v-else-if="step.status == `FAILED`">
<span
- class="h-2.5 w-2.5 rounded-full text-center pb-6 font-medium text-base"
+ class="
+ h-2.5
+ w-2.5
+ rounded-full
+ text-center
+ pb-6
+ font-medium
+ text-base
+ "
aria-hidden="true"
>!</span
>
@@ -115,6 +144,10 @@ export default {
return "bg-white border-2 border-control";
case "PENDING_ACTIVE":
return "bg-white border-2 border-blue-600 text-blue-600";
+ case "PENDING_APPROVAL":
+ return "bg-white border-2 border-control";
+ case "PENDING_APPROVAL_ACTIVE":
+ return "bg-white border-2 border-blue-600 text-blue-600";
case "RUNNING":
return "bg-white border-2 border-blue-600 text-blue-600";
case "DONE":
diff --git a/frontend/src/bbkit/types.ts b/frontend/src/bbkit/types.ts
index af54894cda..5a249e1552 100644
--- a/frontend/src/bbkit/types.ts
+++ b/frontend/src/bbkit/types.ts
@@ -19,6 +19,8 @@ export type BBTabItem = {
export type BBStepStatus =
| "PENDING"
| "PENDING_ACTIVE"
+ | "PENDING_APPROVAL"
+ | "PENDING_APPROVAL_ACTIVE"
| "RUNNING"
| "DONE"
| "FAILED"
diff --git a/frontend/src/components/IssueTable.vue b/frontend/src/components/IssueTable.vue
index 3fac7e4670..9994a58816 100644
--- a/frontend/src/components/IssueTable.vue
+++ b/frontend/src/components/IssueTable.vue
@@ -116,6 +116,7 @@ import {
BBTableColumn,
BBTableSectionDataSource,
BBStep,
+ BBStepStatus,
} from "../bbkit/types";
import IssueStatusIcon from "../components/IssueStatusIcon.vue";
import {
@@ -240,14 +241,18 @@ export default {
const taskList = function (issue: Issue): BBStep[] {
const list: Task[] = allTaskList(issue.pipeline);
return list.map((task) => {
+ let status: BBStepStatus = task.status;
+ if (status == "PENDING" || status == "PENDING_APPROVAL") {
+ if (activeTask(issue.pipeline).id == task.id) {
+ status =
+ status == "PENDING"
+ ? "PENDING_ACTIVE"
+ : "PENDING_APPROVAL_ACTIVE";
+ }
+ }
return {
title: task.name,
- status:
- task.status == "PENDING"
- ? activeTask(issue.pipeline).id == task.id
- ? "PENDING_ACTIVE"
- : "PENDING"
- : task.status,
+ status,
link: (): string => {
return `/issue/${issue.id}`;
},
diff --git a/frontend/src/miragejs/routes/task.js b/frontend/src/miragejs/routes/task.js
index ed9cad05de..3b7ea56974 100644
--- a/frontend/src/miragejs/routes/task.js
+++ b/frontend/src/miragejs/routes/task.js
@@ -62,7 +62,7 @@ export default function configureTask(route) {
return item.id > task.id;
});
- if (followingTask && followingTask.when == "ON_SUCCESS") {
+ if (followingTask && followingTask.status == "PENDING") {
const payload = {
taskId: followingTask.id,
oldStatus: followingTask.status,
diff --git a/frontend/src/plugins/issue/DatabaseCreateTemplate.ts b/frontend/src/plugins/issue/DatabaseCreateTemplate.ts
index c1888ed3b2..77d9e7c883 100644
--- a/frontend/src/plugins/issue/DatabaseCreateTemplate.ts
+++ b/frontend/src/plugins/issue/DatabaseCreateTemplate.ts
@@ -39,8 +39,8 @@ const template: IssueTemplate = {
taskList: [
{
name: "Create database",
+ status: "PENDING_APPROVAL",
type: "bb.task.general",
- when: "MANUAL",
},
],
},
diff --git a/frontend/src/plugins/issue/DatabaseGrantTemplate.ts b/frontend/src/plugins/issue/DatabaseGrantTemplate.ts
index e3762cb519..afb535979b 100644
--- a/frontend/src/plugins/issue/DatabaseGrantTemplate.ts
+++ b/frontend/src/plugins/issue/DatabaseGrantTemplate.ts
@@ -33,8 +33,8 @@ const template: IssueTemplate = {
taskList: [
{
name: "Request database access",
+ status: "PENDING_APPROVAL",
type: "bb.task.general",
- when: "MANUAL",
databaseId: ctx.databaseList[0].id,
},
],
diff --git a/frontend/src/plugins/issue/DatabaseSchemaUpdateTemplate.ts b/frontend/src/plugins/issue/DatabaseSchemaUpdateTemplate.ts
index 511f07cff7..c5f6b414b4 100644
--- a/frontend/src/plugins/issue/DatabaseSchemaUpdateTemplate.ts
+++ b/frontend/src/plugins/issue/DatabaseSchemaUpdateTemplate.ts
@@ -30,8 +30,8 @@ const template: IssueTemplate = {
taskList: [
{
name: `Update ${ctx.databaseList[i].name} schema`,
+ status: "PENDING_APPROVAL",
type: "bb.task.database.schema.update",
- when: "MANUAL",
databaseId: ctx.databaseList[i].id,
},
],
diff --git a/frontend/src/plugins/issue/DefaultTemplate.ts b/frontend/src/plugins/issue/DefaultTemplate.ts
index 75f429e2cc..156603e431 100644
--- a/frontend/src/plugins/issue/DefaultTemplate.ts
+++ b/frontend/src/plugins/issue/DefaultTemplate.ts
@@ -19,8 +19,8 @@ const template: IssueTemplate = {
taskList: [
{
name: "Troubleshoot database",
+ status: "PENDING_APPROVAL",
type: "bb.task.general",
- when: "MANUAL",
databaseId: UNKNOWN_ID,
},
],
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index eba596c1b6..549f775806 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -254,7 +254,6 @@ export const unknown = (
name: "<<Unknown task>>",
type: "bb.task.general",
status: "DONE",
- when: "ON_SUCCESS",
database: UNKNOWN_DATABASE,
taskRunList: [],
};
@@ -494,7 +493,6 @@ export const empty = (
name: "",
type: "bb.task.general",
status: "DONE",
- when: "ON_SUCCESS",
database: EMPTY_DATABASE,
taskRunList: [],
};
diff --git a/frontend/src/types/pipeline.ts b/frontend/src/types/pipeline.ts
index 819ae8e0f0..aa2127a069 100644
--- a/frontend/src/types/pipeline.ts
+++ b/frontend/src/types/pipeline.ts
@@ -190,14 +190,13 @@ export type TaskType = "bb.task.general" | "bb.task.database.schema.update";
export type TaskStatus =
| "PENDING"
+ | "PENDING_APPROVAL"
| "RUNNING"
| "DONE"
| "FAILED"
| "CANCELED"
| "SKIPPED";
-export type TaskWhenType = "ON_SUCCESS" | "MANUAL";
-
export type DatabaseSchemaUpdateTaskPayload = {
sql: string;
rollbackSql: string;
@@ -223,7 +222,6 @@ export type Task = {
name: string;
status: TaskStatus;
type: TaskType;
- when: TaskWhenType;
// We may get an empty database for tasks like creating database.
database: Database;
payload?: TaskPayload;
@@ -232,8 +230,8 @@ export type Task = {
export type TaskCreate = {
// Domain specific fields
name: string;
+ status: TaskStatus;
type: TaskType;
- when: TaskWhenType;
databaseId?: DatabaseId;
};
diff --git a/frontend/src/utils/pipeline.ts b/frontend/src/utils/pipeline.ts
index aece07d0aa..10960adddc 100644
--- a/frontend/src/utils/pipeline.ts
+++ b/frontend/src/utils/pipeline.ts
@@ -193,11 +193,9 @@ const TASK_STATUS_TRANSITION_LIST: Map<
],
]);
-type TaskTransitionStatus = TaskStatus | "PENDING_APPROVAL";
-
// The transition button are displayed from left to right on the UI, and the right-most one is the primary button
const APPLICABLE_TASK_TRANSITION_LIST: Map<
- TaskTransitionStatus,
+ TaskStatus,
TaskStatusTransitionType[]
> = new Map([
["PENDING", ["SKIP", "RUN"]],
@@ -217,13 +215,9 @@ export function applicableTaskTransition(
return [];
}
- const status =
- task.status == "PENDING" && task.when == "MANUAL"
- ? "PENDING_APPROVAL"
- : task.status;
-
- const list: TaskStatusTransitionType[] =
- APPLICABLE_TASK_TRANSITION_LIST.get(status)!;
+ const list: TaskStatusTransitionType[] = APPLICABLE_TASK_TRANSITION_LIST.get(
+ task.status
+ )!;
return list.map((type: TaskStatusTransitionType) => {
return TASK_STATUS_TRANSITION_LIST.get(type)!;
diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vue
index 6fca9c48fe..af5c19e137 100644
--- a/frontend/src/views/IssueDetail.vue
+++ b/frontend/src/views/IssueDetail.vue
@@ -605,7 +605,7 @@ export default {
}
const task = activeTask((issue.value as Issue).pipeline);
- return task.status == "PENDING" && task.when == "MANUAL";
+ return task.status == "PENDING_APPROVAL";
});
const showPipelineFlowBar = computed(() => {
diff --git a/frontend/src/views/PipelineSimpleFlow.vue b/frontend/src/views/PipelineSimpleFlow.vue
index 4fa83a50c3..b775146a5a 100644
--- a/frontend/src/views/PipelineSimpleFlow.vue
+++ b/frontend/src/views/PipelineSimpleFlow.vue
@@ -42,6 +42,22 @@
aria-hidden="true"
></span>
</template>
+ <template v-else-if="item.taskStatus === 'PENDING_APPROVAL'">
+ <svg
+ class="w-4 h-4"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"
+ ></path>
+ </svg>
+ </template>
<template v-else-if="item.taskStatus == 'RUNNING'">
<span
class="h-2.5 w-2.5 bg-blue-600 rounded-full"
@@ -199,6 +215,11 @@ export default {
return "bg-white border-2 border-blue-600 text-blue-600 ";
}
return "bg-white border-2 border-control";
+ case "PENDING_APPROVAL":
+ if (activeTask(props.pipeline).id === item.taskId) {
+ return "bg-white border-2 border-blue-600 text-blue-600";
+ }
+ return "bg-white border-2 border-control";
case "RUNNING":
return "bg-white border-2 border-blue-600 text-blue-600";
case "DONE":
@@ -224,6 +245,7 @@ export default {
case "DONE":
return textClass + "text-control";
case "PENDING":
+ case "PENDING_APPROVAL":
if (activeTask(props.pipeline).id === item.taskId) {
return textClass + "text-blue-600";
}