Skip to content

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

feat(frontend): gh-ost part 1 (#1128)

Liu Ji233dba7d6b5c
diff --git a/frontend/src/bbkit/index.ts b/frontend/src/bbkit/index.ts
index 01b6dc6cac..9b2dc7d3df 100644
--- a/frontend/src/bbkit/index.ts
+++ b/frontend/src/bbkit/index.ts
@@ -11,6 +11,7 @@ import BBNotification from "./BBNotification.vue";
import BBOutline from "./BBOutline.vue";
import BBSelect from "./BBSelect.vue";
import BBComboBox from "./BBComboBox.vue";
+import BBProgressPie from "./BBProgressPie.vue";
import BBSpin from "./BBSpin.vue";
import BBStepBar from "./BBStepBar.vue";
import BBStepTab from "./BBStepTab.vue";
@@ -40,6 +41,7 @@ export {
BBOutline,
BBSelect,
BBComboBox,
+ BBProgressPie,
BBSpin,
BBStepBar,
BBStepTab,
diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vue
index 45cfdbf1b2..bc91db23e5 100644
--- a/frontend/src/components/Issue/IssueDetailLayout.vue
+++ b/frontend/src/components/Issue/IssueDetailLayout.vue
@@ -52,6 +52,19 @@
@select-task="selectTask"
/>
</template>
+ <template v-else-if="isGhostMode">
+ <PipelineGhostFlow
+ v-if="project"
+ :create="create"
+ :project="project"
+ :pipeline="issue.pipeline!"
+ :selected-stage="selectedStage"
+ :selected-task="selectedTask"
+ class="border-t border-b"
+ @select-stage-id="selectStageId"
+ @select-task="selectTask"
+ />
+ </template>
<template v-else>
<PipelineSimpleFlow
:create="create"
@@ -60,11 +73,13 @@
@select-stage-id="selectStageId"
/>
</template>
+
<div v-if="!create" class="px-4 py-4 md:flex md:flex-col border-b">
<IssueStagePanel
:stage="selectedStage"
:selected-task="selectedTask"
- :single-mode="isTenantDeployMode"
+ :is-tenant-mode="isTenantDeployMode"
+ :is-ghost-mode="isGhostMode"
/>
</div>
</template>
@@ -142,6 +157,27 @@
@update-statement="updateStatement"
/>
</template>
+ <template v-else-if="isGhostMode">
+ <!--
+ For gh-ost mode, only the first task (bb.task.database.schema.update.ghost.sync)
+ has a SQL statement.
+ TODO(jim): When the other two tasks are selected we should show the SQL which will be internally
+ executed (change table name and drop table).
+ -->
+ <template v-if="isGhostSyncTaskSelected">
+ <IssueTaskStatementPanel
+ :sql-hint="sqlHint()"
+ :statement="selectedStatement"
+ :create="create"
+ :allow-edit="allowEditStatement"
+ :show-apply-statement="showIssueTaskStatementApply"
+ @update-statement="updateStatement"
+ @apply-statement-to-other-stages="
+ applyStatementToOtherStages
+ "
+ />
+ </template>
+ </template>
<template v-else>
<!-- The way this is written is awkward and is to workaround an issue in IssueTaskStatementPanel.
The statement panel is in non-edit mode when not creating the issue, and we use v-highlight
@@ -227,6 +263,7 @@ import {
stageSlug,
activeTask,
taskSlug,
+ isDev,
} from "../../utils";
import IssueBanner from "./IssueBanner.vue";
import IssueHighlightPanel from "./IssueHighlightPanel.vue";
@@ -239,6 +276,7 @@ import IssueDescriptionPanel from "./IssueDescriptionPanel.vue";
import IssueActivityPanel from "./IssueActivityPanel.vue";
import PipelineSimpleFlow from "./PipelineSimpleFlow.vue";
import PipelineTenantFlow from "./PipelineTenantFlow.vue";
+import PipelineGhostFlow from "./PipelineGhostFlow.vue";
import TaskCheckBar from "./TaskCheckBar.vue";
import {
Issue,
@@ -266,6 +304,7 @@ import {
TaskPatch,
UpdateSchemaContext,
UpdateSchemaDetail,
+ TaskDatabaseSchemaUpdateGhostSyncPayload,
} from "../../types";
import {
defaulTemplate as defaultTemplate,
@@ -298,6 +337,7 @@ export default defineComponent({
IssueStatusTransitionButtonGroup,
PipelineSimpleFlow,
PipelineTenantFlow,
+ PipelineGhostFlow,
TaskCheckBar,
},
props: {
@@ -406,6 +446,7 @@ export default defineComponent({
task.type == "bb.task.general" ||
task.type == "bb.task.database.create" ||
task.type == "bb.task.database.schema.update" ||
+ task.type == "bb.task.database.schema.update.ghost.sync" ||
task.type == "bb.task.database.data.update"
) {
task.statement = newStatement;
@@ -731,18 +772,36 @@ export default defineComponent({
);
case "bb.task.database.restore":
return "";
+ case "bb.task.database.schema.update.ghost.sync":
+ case "bb.task.database.schema.update.ghost.cutover":
+ case "bb.task.database.schema.update.ghost.drop-original-table":
+ return ""; // should never reach here
}
};
const isTenantDeployMode = computed((): boolean => {
+ if (project.value.tenantMode !== "TENANT") return false;
+ return (
+ props.issue.type === "bb.issue.database.schema.update" ||
+ props.issue.type === "bb.issue.database.data.update"
+ );
+ });
+
+ const isGhostMode = computed((): boolean => {
+ if (!isDev()) return false;
+
+ return props.issue.type === "bb.issue.database.schema.update.ghost";
+ });
+
+ const isGhostSyncTaskSelected = computed((): boolean => {
return (
- props.issue.type === "bb.issue.database.schema.update" &&
- project.value.tenantMode === "TENANT"
+ selectedTask.value.type === "bb.task.database.schema.update.ghost.sync"
);
});
const selectedStatement = computed((): string => {
if (isTenantDeployMode.value) {
+ // In tenant mode, the entire issue shares only one SQL statement
if (props.create) {
const issueCreate = props.issue as IssueCreate;
const context = issueCreate.createContext as UpdateSchemaContext;
@@ -753,6 +812,21 @@ export default defineComponent({
const payload = task.payload as TaskDatabaseSchemaUpdatePayload;
return payload.statement;
}
+ } else if (isGhostMode.value) {
+ // In gh-ost mode, each stage can own its SQL statement
+ // But only for task.type === "bb.task.database.schema.update.ghost.sync"
+ const task = selectedTask.value;
+ if (task.type === "bb.task.database.schema.update.ghost.sync") {
+ if (props.create) {
+ return (task as TaskCreate).statement;
+ } else {
+ const payload = (task as Task)
+ .payload as TaskDatabaseSchemaUpdateGhostSyncPayload;
+ return payload.statement;
+ }
+ } else {
+ return "";
+ }
} else {
if (router.currentRoute.value.query.sql) {
const sql = router.currentRoute.value.query.sql as string;
@@ -875,6 +949,7 @@ export default defineComponent({
task.type == "bb.task.general" ||
task.type == "bb.task.database.create" ||
task.type == "bb.task.database.schema.update" ||
+ task.type == "bb.task.database.schema.update.ghost.sync" ||
task.type == "bb.task.database.data.update"
);
});
@@ -893,6 +968,7 @@ export default defineComponent({
task.type == "bb.task.general" ||
task.type == "bb.task.database.create" ||
task.type == "bb.task.database.schema.update" ||
+ task.type == "bb.task.database.schema.update.ghost.sync" ||
task.type == "bb.task.database.data.update"
) {
count++;
@@ -974,6 +1050,8 @@ export default defineComponent({
currentUser,
project,
isTenantDeployMode,
+ isGhostMode,
+ isGhostSyncTaskSelected,
issueTemplate,
selectedStage,
selectedTask,
diff --git a/frontend/src/components/Issue/IssueStagePanel.vue b/frontend/src/components/Issue/IssueStagePanel.vue
index f42d863eb0..4aee55f880 100644
--- a/frontend/src/components/Issue/IssueStagePanel.vue
+++ b/frontend/src/components/Issue/IssueStagePanel.vue
@@ -1,38 +1,38 @@
<template>
<div class="space-y-4">
- <div v-for="(task, index) in filteredTaskList" :key="index">
- <div class="flex flex-row items-center space-x-1">
- <heroicons-solid:arrow-narrow-right
- v-if="
- !singleMode &&
- filteredTaskList.length > 1 &&
- activeTask.id == task.id
- "
- class="w-5 h-5 text-info"
- />
- <div
- v-if="!singleMode && filteredTaskList.length > 1"
- class="textlabel"
- >
- <span v-if="filteredTaskList.length > 1">
- Step {{ index + 1 }} -
- </span>
- {{ task.name }}
+ <template v-if="mode === 'single'">
+ <TaskRunTable :task-list="[selectedTask || stage.taskList[0]]" />
+ </template>
+ <template v-else-if="mode === 'merged'">
+ <TaskRunTable :task-list="stage.taskList" />
+ </template>
+ <template v-else>
+ <template v-for="(task, index) in stage.taskList" :key="index">
+ <div class="flex flex-row items-center space-x-1">
+ <heroicons-solid:arrow-narrow-right
+ v-if="stage.taskList.length > 1 && activeTask.id == task.id"
+ class="w-5 h-5 text-info"
+ />
+ <div v-if="stage.taskList.length > 1" class="textlabel">
+ <span v-if="stage.taskList.length > 1">
+ Step {{ index + 1 }} -
+ </span>
+ {{ task.name }}
+ </div>
</div>
- </div>
- <TaskRunTable :task="task" />
- </div>
+ <TaskRunTable :task-list="[task]" />
+ </template>
+ </template>
</div>
</template>
<script lang="ts">
-import { reactive, PropType, computed, defineComponent } from "vue";
+import { PropType, computed, defineComponent } from "vue";
import TaskRunTable from "./TaskRunTable.vue";
import { Stage, Task } from "../../types";
import { activeTaskInStage } from "../../utils";
-// eslint-disable-next-line @typescript-eslint/no-empty-interface
-interface LocalState {}
+type Mode = "normal" | "single" | "merged";
export default defineComponent({
name: "IssueStagePanel",
@@ -46,29 +46,34 @@ export default defineComponent({
type: Object as PropType<Task>,
default: undefined,
},
- singleMode: {
+ isTenantMode: {
+ type: Boolean,
+ default: false,
+ },
+ isGhostMode: {
type: Boolean,
default: false,
},
},
setup(props) {
- const state = reactive<LocalState>({});
-
const activeTask = computed((): Task => {
return activeTaskInStage(props.stage);
});
- const filteredTaskList = computed(() => {
- if (props.singleMode && props.selectedTask) {
- return [props.selectedTask];
- }
- return props.stage.taskList;
+ /**
+ * normal mode: display multiple tables for each task in stage.taskList
+ * merged mode: merge all tasks' activities into one table
+ * single mode: show only selected task's activities
+ */
+ const mode = computed((): Mode => {
+ if (props.isGhostMode) return "merged";
+ if (props.isTenantMode) return "single";
+ return "normal";
});
return {
- state,
activeTask,
- filteredTaskList,
+ mode,
};
},
});
diff --git a/frontend/src/components/Issue/PipelineGhostFlow.vue b/frontend/src/components/Issue/PipelineGhostFlow.vue
new file mode 100644
index 0000000000..e7bea31081
--- /dev/null
+++ b/frontend/src/components/Issue/PipelineGhostFlow.vue
@@ -0,0 +1,367 @@
+<template>
+ <div class="w-full">
+ <div class="lg:flex divide-y lg:divide-y-0 border-b">
+ <div
+ v-for="(stage, i) in pipeline.stageList"
+ :key="i"
+ class="stage-wrapper flex-1 md:flex md:flex-col items-center justify-start"
+ >
+ <div class="stage-header" :class="stageClass(stage)">
+ <span class="pl-4 py-2 flex items-center text-sm font-medium">
+ <TaskStatusIcon
+ :create="create"
+ :active="isActiveStage(stage)"
+ :status="taskStatusOfStage(stage)"
+ />
+ <div
+ class="text cursor-pointer hover:underline hidden lg:ml-4 lg:flex lg:flex-col"
+ >
+ <span class="text-xs">{{ stage.name }}</span>
+ <span class="text-sm">{{ taskNameOfStage(stage) }}</span>
+ </div>
+ <div
+ class="text ml-4 cursor-pointer flex items-center space-x-2 lg:hidden"
+ >
+ <span class="text-sm min-w-32">{{ stage.name }}</span>
+ <span class="text-sm flex-1">{{ taskNameOfStage(stage) }}</span>
+ </div>
+ <div class="tooltip-wrapper">
+ <span class="tooltip whitespace-nowrap">
+ Missing SQL statement
+ </span>
+ <span
+ v-if="!isValidStage(stage)"
+ class="ml-2 w-5 h-5 flex justify-center rounded-full select-none bg-error text-white hover:bg-error-hover"
+ >
+ <span class="text-center font-normal" aria-hidden="true">
+ !
+ </span>
+ </span>
+ </div>
+ </span>
+
+ <!-- Arrow separator -->
+ <div
+ v-if="i < pipeline.stageList.length - 1"
+ class="hidden lg:block absolute top-0 right-0 h-full w-5"
+ aria-hidden="true"
+ >
+ <svg
+ class="h-full w-full text-gray-300"
+ viewBox="0 0 22 80"
+ fill="none"
+ preserveAspectRatio="none"
+ >
+ <path
+ d="M0 -2L20 40L0 82"
+ vector-effect="non-scaling-stroke"
+ stroke="currentcolor"
+ stroke-linejoin="round"
+ />
+ </svg>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!--
+ We don't parse the tasks' dependency relationships here, since we have exactly 1
+ [sync->cutover->drop-original-table] thread in each stage.
+
+ If we support multi-tenant-gh-ost mode in the future, we may have more than
+ one series of [sync->cutover->drop-original-table] threads.
+ Then we may repeat the horizon scroller. Each row is a thread of gh-ost migration.
+ -->
+ <NScrollbar x-scrollable>
+ <div class="task-list p-2 md:flex md:items-center relative">
+ <template v-for="(task, j) in taskList" :key="j">
+ <div
+ class="task px-2 py-1 cursor-pointer border rounded md:w-64 flex justify-between items-center"
+ :class="taskClass(task)"
+ @click="
+ onClickTask(selectedStageId, task.name, create ? j + 1 : task.id)
+ "
+ >
+ <div class="flex-1">
+ <div class="flex items-center pb-1">
+ <TaskStatusIcon
+ :create="create"
+ :active="isActiveTask(task)"
+ :status="task.status"
+ class="transform scale-75"
+ />
+ <heroicons-solid:arrow-narrow-right
+ v-if="isActiveTask(task)"
+ class="name w-5 h-5"
+ />
+ <div class="name">{{ databaseOfTask(task).name }}</div>
+ </div>
+ <div
+ class="flex items-center px-1 py-1 whitespace-pre-wrap break-all"
+ >
+ {{ taskNameOfTask(task) }}
+ </div>
+ </div>
+ <div v-if="getTaskProgress(task) > 0">
+ <BBProgressPie
+ class="w-9 h-9 text-info"
+ :thickness="2"
+ :percent="getTaskProgress(task)"
+ >
+ <template #default="{ percent }">
+ <span class="text-xs scale-90">{{ percent }}%</span>
+ </template>
+ </BBProgressPie>
+ </div>
+ </div>
+
+ <div
+ v-if="j < taskList.length - 1"
+ class="hidden md:flex items-center justify-center w-4 h-2 overflow-visible relative"
+ >
+ <!-- show an arrow indicator between tasks -->
+ <heroicons-outline:chevron-right class="w-4 h-4" />
+ </div>
+ </template>
+ </div>
+
+ <div class="absolute right-0 top-0 bottom-0 w-10 hidden md:block"></div>
+ </NScrollbar>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computed, PropType, watchEffect } from "vue";
+import {
+ Pipeline,
+ Stage,
+ StageCreate,
+ PipelineCreate,
+ Task,
+ TaskCreate,
+ Project,
+ Database,
+} from "@/types";
+import { activeTask, activeTaskInStage, taskSlug } from "@/utils";
+import { isEmpty } from "lodash-es";
+import TaskStatusIcon from "./TaskStatusIcon.vue";
+import { useDatabaseStore } from "@/store";
+import { NScrollbar } from "naive-ui";
+import { BBProgressPie } from "@/bbkit";
+import { useI18n } from "vue-i18n";
+
+const props = defineProps({
+ create: {
+ required: true,
+ type: Boolean,
+ },
+ project: {
+ required: true,
+ type: Object as PropType<Project>,
+ },
+ pipeline: {
+ required: true,
+ type: Object as PropType<Pipeline | PipelineCreate>,
+ },
+ selectedStage: {
+ required: true,
+ type: Object as PropType<Stage | StageCreate>,
+ },
+ selectedTask: {
+ type: Object as PropType<Task | TaskCreate | undefined>,
+ default: undefined,
+ },
+});
+
+const emit = defineEmits<{
+ (e: "select-task", stageIdOrIndex: number, taskSlug: string): void;
+}>();
+
+const { t } = useI18n();
+const databaseStore = useDatabaseStore();
+
+watchEffect(function prepare() {
+ if (props.create) {
+ databaseStore.fetchDatabaseListByProjectId(props.project.id);
+ }
+});
+
+const databaseOfTask = (task: Task | TaskCreate): Database => {
+ if (props.create) {
+ return databaseStore.getDatabaseById((task as TaskCreate).databaseId!);
+ }
+ return (task as Task).database!;
+};
+
+const isSelectedStage = (stage: Stage | StageCreate): boolean => {
+ return stage === props.selectedStage;
+};
+
+const isSelectedTask = (task: Task | TaskCreate): boolean => {
+ return task === props.selectedTask;
+};
+
+const isActiveStage = (stage: Stage | StageCreate): boolean => {
+ if (props.create) {
+ return false;
+ }
+
+ const task = activeTaskInStage(stage as Stage);
+ if (activeTask(props.pipeline as Pipeline).id === task.id) {
+ return true;
+ }
+ return false;
+};
+
+const isActiveTask = (task: Task | TaskCreate): boolean => {
+ if (props.create) {
+ return false;
+ }
+ task = task as Task;
+ return activeTask(props.pipeline as Pipeline).id === task.id;
+};
+
+const taskStatusOfStage = (stage: Stage | StageCreate) => {
+ if (props.create) {
+ return stage.taskList[0].status;
+ }
+ const activeTask = activeTaskInStage(stage as Stage);
+ return activeTask.status;
+};
+
+const taskNameOfStage = (stage: Stage | StageCreate) => {
+ if (props.create) {
+ return stage.taskList[0].status;
+ }
+ const activeTask = activeTaskInStage(stage as Stage);
+ const { taskList } = stage as Stage;
+ for (let i = 0; i < stage.taskList.length; i++) {
+ if (taskList[i].id == activeTask.id) {
+ return `${activeTask.name} (${i + 1}/${stage.taskList.length})`;
+ }
+ }
+ return activeTask.name;
+};
+
+const taskNameOfTask = (task: Task | TaskCreate) => {
+ return t(`task.type.${task.type.replace(/\./g, "-")}`);
+};
+
+const isValidStage = (stage: Stage | StageCreate) => {
+ if (!props.create) {
+ return true;
+ }
+ for (const task of (stage as StageCreate).taskList) {
+ if (task.type === "bb.task.database.schema.update.ghost.sync") {
+ if (isEmpty(task.statement)) {
+ return false;
+ }
+ }
+ }
+ return true;
+};
+
+const taskList = computed(() => {
+ return props.selectedStage.taskList;
+});
+
+const selectedStageId = computed(() => {
+ if (!props.create) {
+ return (props.selectedStage as Stage).id;
+ }
+ return (props.pipeline.stageList as StageCreate[]).indexOf(
+ props.selectedStage as StageCreate
+ );
+});
+
+const getTaskProgress = (task: Task | TaskCreate) => {
+ if (props.create) {
+ return 0;
+ }
+ if (task.type !== "bb.task.database.schema.update.ghost.sync") return 0;
+ const progress = 66.6; // TODO(jim): not implemented yet
+ return progress;
+};
+
+const stageClass = (stage: Stage | StageCreate): string[] => {
+ const classes: string[] = [];
+ if (props.create) classes.push("create");
+ if (isSelectedStage(stage)) classes.push("selected");
+ if (isActiveStage(stage)) classes.push("active");
+ const task = activeTaskInStage(stage as Stage);
+ classes.push(`status_${task.status.toLowerCase()}`);
+
+ return classes;
+};
+
+const taskClass = (task: Task | TaskCreate): string[] => {
+ const classes: string[] = [];
+ if (isSelectedTask(task)) classes.push("selected");
+ if (isActiveTask(task)) classes.push("active");
+ if (props.create) classes.push("create");
+ classes.push(`status_${task.status.toLowerCase()}`);
+ return classes;
+};
+
+const onClickTask = (stageId: number, taskName: string, taskId: number) => {
+ const ts = taskSlug(taskName, taskId);
+ emit("select-task", stageId, ts);
+};
+</script>
+
+<style scoped lang="postcss">
+.stage-header {
+ @apply cursor-default flex items-center justify-start w-full relative;
+}
+
+.stage-header.selected .text {
+ @apply underline;
+}
+.stage-header.active .text {
+ @apply font-bold;
+}
+.stage-header.status_done .text {
+ @apply text-control;
+}
+.stage-header.status_pending .text,
+.stage-header.status_pending_approval .text {
+ @apply text-control;
+}
+.stage-header.active.status_pending .text,
+.stage-header.active.status_pending_approval .text {
+ @apply text-info;
+}
+.stage-header.status_running .text {
+ @apply text-info;
+}
+.stage-header.status_failed .text {
+ @apply text-red-500;
+}
+
+.task.selected {
+ @apply border-info;
+}
+.task .name {
+ @apply ml-1 overflow-x-hidden whitespace-nowrap overflow-ellipsis;
+}
+.task.active .name {
+ @apply font-bold;
+}
+.task.status_done .name {
+ @apply text-control;
+}
+.task.status_pending .name,
+.task.status_pending_approval .name {
+ @apply text-control;
+}
+.task.active.status_pending .name,
+.task.active.status_pending_approval .name {
+ @apply text-info;
+}
+.task.status_running .name {
+ @apply text-info;
+}
+.task.status_failed .name {
+ @apply text-red-500;
+}
+</style>
diff --git a/frontend/src/components/Issue/TaskRunTable.vue b/frontend/src/components/Issue/TaskRunTable.vue
index 2a7e25e9ad..28182dc100 100644
--- a/frontend/src/components/Issue/TaskRunTable.vue
+++ b/frontend/src/components/Issue/TaskRunTable.vue
@@ -1,13 +1,15 @@
<template>
<BBTable
:column-list="columnList"
- :data-source="task.taskRunList"
+ :data-source="mergedTaskRunList"
:show-header="true"
:left-bordered="true"
:right-bordered="true"
:row-clickable="false"
>
- <template #body="{ rowData: taskRun }">
+ <template
+ #body="{ rowData: { task, taskRun } }: { rowData: MergedTaskRunItem }"
+ >
<BBTableCell :left-padding="4" class="table-cell w-4">
<div class="flex flex-row space-x-2">
<div
@@ -39,11 +41,11 @@
</BBTableCell>
<BBTableCell class="table-cell w-36">
{{ comment(taskRun) }}
- <template v-if="commentLink(taskRun).link">
+ <template v-if="commentLink(task, taskRun).link">
<router-link
class="ml-1 normal-link"
- :to="commentLink(taskRun).link"
- >{{ commentLink(taskRun).title }}</router-link
+ :to="commentLink(task, taskRun).link"
+ >{{ commentLink(task, taskRun).title }}</router-link
>
</template>
</BBTableCell>
@@ -69,8 +71,8 @@
</BBTable>
</template>
-<script lang="ts">
-import { computed, defineComponent, PropType } from "vue";
+<script lang="ts" setup>
+import { computed, PropType } from "vue";
import PrincipalAvatar from "../PrincipalAvatar.vue";
import { BBTableColumn } from "../../bbkit/types";
import { MigrationErrorCode, Task, TaskRun, TaskRunStatus } from "../../types";
@@ -82,103 +84,111 @@ type CommentLink = {
link: string;
};
-export default defineComponent({
- name: "TaskRunTable",
- components: { PrincipalAvatar },
- props: {
- task: {
- required: true,
- type: Object as PropType<Task>,
- },
+type MergedTaskRunItem = {
+ task: Task;
+ taskRun: TaskRun;
+};
+
+const props = defineProps({
+ taskList: {
+ required: true,
+ type: Array as PropType<Task[]>,
},
- setup(props) {
- const { t } = useI18n();
+});
- const columnList = computed((): BBTableColumn[] => [
- {
- title: "",
- },
- {
- title: t("task.comment"),
- },
- {
- title: t("task.invoker"),
- },
- {
- title: t("task.started"),
- },
- {
- title: t("task.ended"),
- },
- ]);
+const { t } = useI18n();
- const statusIconClass = (status: TaskRunStatus) => {
- switch (status) {
- case "RUNNING":
- return "bg-white border-2 border-info text-info";
- case "DONE":
- return "bg-success text-white";
- case "FAILED":
- return "bg-error text-white";
- case "CANCELED":
- return "bg-white border-2 border-gray-400 text-gray-400";
- }
- };
+const columnList = computed((): BBTableColumn[] => [
+ {
+ title: "",
+ },
+ {
+ title: t("task.comment"),
+ },
+ {
+ title: t("task.invoker"),
+ },
+ {
+ title: t("task.started"),
+ },
+ {
+ title: t("task.ended"),
+ },
+]);
- const comment = (taskRun: TaskRun): string => {
- if (taskRun.status == "FAILED") {
- return taskRun.result.detail;
- }
- // Returns result detail if we get the result, otherwise, returns the comment.
- return taskRun.result.detail || taskRun.comment;
- };
+const mergedTaskRunList = computed(() => {
+ const taskRunList: MergedTaskRunItem[] = [];
+ props.taskList.forEach((task) => {
+ task.taskRunList.forEach((taskRun) => {
+ taskRunList.push({ task, taskRun });
+ });
+ });
+ taskRunList.sort((a, b) => {
+ return a.taskRun.updatedTs - b.taskRun.updatedTs;
+ });
+
+ return taskRunList;
+});
+
+const statusIconClass = (status: TaskRunStatus) => {
+ switch (status) {
+ case "RUNNING":
+ return "bg-white border-2 border-info text-info";
+ case "DONE":
+ return "bg-success text-white";
+ case "FAILED":
+ return "bg-error text-white";
+ case "CANCELED":
+ return "bg-white border-2 border-gray-400 text-gray-400";
+ }
+};
- const commentLink = (taskRun: TaskRun): CommentLink => {
- if (taskRun.status == "DONE") {
- switch (taskRun.type) {
- case "bb.task.database.schema.update":
- case "bb.task.database.data.update": {
- return {
- title: t("task.view-migration"),
- link: `/db/${databaseSlug(
- props.task.database!
- )}/history/${migrationHistorySlug(
- taskRun.result.migrationId!,
- taskRun.result.version!
- )}`,
- };
- }
- }
- } else if (taskRun.status == "FAILED") {
- if (taskRun.code == MigrationErrorCode.MIGRATION_SCHEMA_MISSING) {
- return {
- title: "Check instance",
- link: `/instance/${instanceSlug(props.task.instance)}`,
- };
- } else if (
- props.task.database &&
- (taskRun.code == MigrationErrorCode.MIGRAITON_ALREADY_APPLIED ||
- taskRun.code == MigrationErrorCode.MGIRATION_OUT_OF_ORDER ||
- taskRun.code == MigrationErrorCode.MIGRATION_BASELINE_MISSING)
- ) {
- return {
- title: t("task.view-migration-history"),
- link: `/db/${databaseSlug(props.task.database!)}#migration-history`,
- };
- }
+const comment = (taskRun: TaskRun): string => {
+ if (taskRun.status == "FAILED") {
+ return taskRun.result.detail;
+ }
+ // Returns result detail if we get the result, otherwise, returns the comment.
+ return taskRun.result.detail || taskRun.comment;
+};
+
+const commentLink = (task: Task, taskRun: TaskRun): CommentLink => {
+ if (taskRun.status == "DONE") {
+ switch (taskRun.type) {
+ case "bb.task.database.schema.update":
+ case "bb.task.database.data.update": {
+ return {
+ title: t("task.view-migration"),
+ link: `/db/${databaseSlug(
+ task.database!
+ )}/history/${migrationHistorySlug(
+ taskRun.result.migrationId!,
+ taskRun.result.version!
+ )}`,
+ };
}
+ // TODO(jim): format for gh-ost related tasks
+ }
+ } else if (taskRun.status == "FAILED") {
+ if (taskRun.code == MigrationErrorCode.MIGRATION_SCHEMA_MISSING) {
return {
- title: "",
- link: "",
+ title: "Check instance",
+ link: `/instance/${instanceSlug(task.instance)}`,
};
- };
-
- return {
- columnList,
- statusIconClass,
- comment,
- commentLink,
- };
- },
-});
+ } else if (
+ task.database &&
+ (taskRun.code == MigrationErrorCode.MIGRAITON_ALREADY_APPLIED ||
+ taskRun.code == MigrationErrorCode.MGIRATION_OUT_OF_ORDER ||
+ taskRun.code == MigrationErrorCode.MIGRATION_BASELINE_MISSING)
+ ) {
+ return {
+ title: t("task.view-migration-history"),
+ link: `/db/${databaseSlug(task.database!)}#migration-history`,
+ };
+ }
+ }
+ return {
+ title: "",
+ link: "",
+ };
+};
</script>
diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.yml
index eb9dcda8a7..4f2afb4e6e 100644
--- a/frontend/src/locales/en.yml
+++ b/frontend/src/locales/en.yml
@@ -229,6 +229,10 @@ task:
earliest-allowed-time-no-modify: >-
You can not modify this field because you are not the issue assignee or it's
not pending to run.
+ type:
+ bb-task-database-schema-update-ghost-sync: Sync data
+ bb-task-database-schema-update-ghost-cutover: Switch tables
+ bb-task-database-schema-update-ghost-drop-original-table: Drop original table
banner:
demo-intro: This is a demo version of Bytebase.
demo-intro-readonly: This is a demo version of Bytebase in read-only mode.
diff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.yml
index 9bda513def..16260af2e9 100644
--- a/frontend/src/locales/zh-CN.yml
+++ b/frontend/src/locales/zh-CN.yml
@@ -224,6 +224,10 @@ task:
warn: 警告
error: 错误
earliest-allowed-time-no-modify: 您无法修改此字段因为您不是该工单的审核人或者它不在待执行状态。
+ type:
+ bb-task-database-schema-update-ghost-sync: 同步数据
+ bb-task-database-schema-update-ghost-cutover: 切换表
+ bb-task-database-schema-update-ghost-drop-original-table: 删除原始表
banner:
demo-intro: 这是 Bytebase 的演示版本。
demo-intro-readonly: 这是 Bytebase 的只读演示版本
diff --git a/frontend/src/store/modules/pipeline.ts b/frontend/src/store/modules/pipeline.ts
index 50930f53f3..6d8edc89e1 100644
--- a/frontend/src/store/modules/pipeline.ts
+++ b/frontend/src/store/modules/pipeline.ts
@@ -5,6 +5,10 @@ import {
Pipeline,
PipelineState,
Stage,
+ TaskId,
+ Task,
+ Attributes,
+ unknown,
} from "@/types";
import { getPrincipalFromIncludedList } from "./principal";
import { useStageStore } from "./stage";
@@ -55,6 +59,27 @@ function convert(
}
}
+ // Then we compose tasks' blockedBy since we have converted all tasks in this pipeline
+ const taskMapById = new Map<TaskId, Task>();
+ result.stageList.forEach((stage) =>
+ stage.taskList.forEach((task) => {
+ taskMapById.set(task.id, task);
+ })
+ );
+ result.stageList.forEach((stage) =>
+ stage.taskList.forEach((task) => {
+ // attributes.blockedBy is string[] since jsonapi's limitation
+ const blockedByTaskIdList = (task as Attributes).blockedBy as string[];
+ const blockedBy = (blockedByTaskIdList || []).map((blockedById) => {
+ return (
+ taskMapById.get(parseInt(blockedById, 10)) ||
+ (unknown("TASK") as Task)
+ );
+ });
+ task.blockedBy = blockedBy;
+ })
+ );
+
return result;
}
export const usePipelineStore = defineStore("pipeline", {
diff --git a/frontend/src/types/pipeline/task.ts b/frontend/src/types/pipeline/task.ts
index 1e327479fa..81634bcece 100644
--- a/frontend/src/types/pipeline/task.ts
+++ b/frontend/src/types/pipeline/task.ts
@@ -114,6 +114,9 @@ export type Task = {
// Tasks like creating database may not have database.
database?: Database;
payload?: TaskPayload;
+
+ // Task DAG
+ blockedBy: Task[];
};
export type TaskCreate = {