Skip to content

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

Introduce TaskPatch model for patchng Task

Tianzhou Chen62a86f82f1f4
diff --git a/frontend/src/miragejs/factories/index.js b/frontend/src/miragejs/factories/index.js
index e7c95b3f89..f8c20cd2cd 100644
--- a/frontend/src/miragejs/factories/index.js
+++ b/frontend/src/miragejs/factories/index.js
@@ -13,6 +13,7 @@ import repository from "./repository";
import job from "./job";
import step from "./step";
import task from "./task";
+import taskPatch from "./taskPatch";
import group from "./group";
import workspace from "./workspace";
import workspaceRole from "./workspaceRole";
@@ -37,6 +38,7 @@ export default {
...job,
...step,
...task,
+ ...taskPatch,
...group,
...workspace,
...workspaceRole,
diff --git a/frontend/src/miragejs/factories/taskPatch.js b/frontend/src/miragejs/factories/taskPatch.js
new file mode 100644
index 0000000000..c47b349bc4
--- /dev/null
+++ b/frontend/src/miragejs/factories/taskPatch.js
@@ -0,0 +1,31 @@
+import { Factory } from "miragejs";
+import faker from "faker";
+
+export default {
+ taskPatch: Factory.extend({
+ name(i) {
+ return faker.fake("{{lorem.sentence}}");
+ },
+ status() {
+ return "RUNNING";
+ },
+ content() {
+ return faker.fake("{{lorem.paragraphs}}");
+ },
+ assignee() {
+ return {
+ id: "200",
+ name: "Jim Gray",
+ };
+ },
+ payload() {
+ return {
+ type: "bytebase.datasource.create",
+ fieldList: {
+ // Requested Database name
+ 1: "Mydb",
+ },
+ };
+ },
+ }),
+};
diff --git a/frontend/src/miragejs/models/index.js b/frontend/src/miragejs/models/index.js
index 993f164032..527994bd61 100644
--- a/frontend/src/miragejs/models/index.js
+++ b/frontend/src/miragejs/models/index.js
@@ -53,6 +53,8 @@ export default {
workspace: belongsTo(),
}),
+ taskPatch: Model,
+
environment: Model.extend({
workspace: belongsTo(),
}),
diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.js
index 9c97c97150..0af783b429 100644
--- a/frontend/src/miragejs/routes/index.js
+++ b/frontend/src/miragejs/routes/index.js
@@ -92,9 +92,9 @@ export default function routes() {
});
this.patch("/task/:taskId", function (schema, request) {
- const attrs = this.normalizedRequestAttrs("task");
+ const attrs = this.normalizedRequestAttrs("task-patch");
return schema.tasks
- .find(request.params.environmentId)
+ .find(request.params.taskId)
.update({ ...attrs, lastUpdatedTs: Date.now() });
});
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.ts
index c013daa3c8..29b6c9351c 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/modules/task.ts
@@ -1,5 +1,12 @@
import axios from "axios";
-import { UserId, TaskId, Task, TaskNew, TaskState } from "../../types";
+import {
+ UserId,
+ TaskId,
+ Task,
+ TaskNew,
+ TaskPatch,
+ TaskState,
+} from "../../types";
const state: () => TaskState = () => ({
taskListByUser: new Map(),
@@ -47,15 +54,27 @@ const actions = {
return createdTask;
},
- async patchTask({ commit }: any, task: Task) {
+ async patchTask(
+ { commit }: any,
+ {
+ taskId,
+ taskPatch,
+ }: {
+ taskId: TaskId;
+ taskPatch: TaskPatch;
+ }
+ ) {
const updatedTask = (
- await axios.patch(`/api/task/${task.id}`, {
- data: task,
+ await axios.patch(`/api/task/${taskId}`, {
+ data: {
+ type: "taskpatch",
+ attributes: taskPatch,
+ },
})
).data.data;
commit("setTaskById", {
- taskId: task.id,
+ taskId: taskId,
task: updatedTask,
});
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index b466bba135..aaba1a9261 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -58,12 +58,14 @@ export type StageProgress = {
| "SKIPPED";
};
+export type TaskStatus = "PENDING" | "RUNNING" | "DONE" | "FAILED" | "CANCELED";
+
export type Task = ResourceObject & {
attributes: {
name: string;
createdTs: number;
lastUpdatedTs: number;
- status: "PENDING" | "RUNNING" | "DONE" | "FAILED" | "CANCELED";
+ status: TaskStatus;
category: "DDL" | "DML" | "OPS";
type: TaskType;
content: string;
@@ -100,6 +102,17 @@ export type TaskNew = Omit<ResourceObject, "id"> & {
};
};
+export type TaskPatch = {
+ name?: string;
+ status?: TaskStatus;
+ content?: string;
+ assignee?: {
+ id: string;
+ name: string;
+ };
+ payload?: any;
+};
+
export type Environment = ResourceObject & {
attributes: {
name: string;