Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(frontend): A simple implementation of PITR issue UI (#1311)
Liu Ji1440fb727b50
diff --git a/frontend/src/components/DatabaseDetail/PITRRestoreButton.vue b/frontend/src/components/DatabaseDetail/PITRRestoreButton.vueindex dce431d0a0..55c55599ce 100644--- a/frontend/src/components/DatabaseDetail/PITRRestoreButton.vue+++ b/frontend/src/components/DatabaseDetail/PITRRestoreButton.vue@@ -2,12 +2,12 @@<BBTooltipButtontype="normal"tooltip-mode="DISABLED-ONLY"- :disabled="!allowAdmin || !pitrAvailable"+ :disabled="!allowAdmin || !pitrAvailable.result"@click="state.showDatabasePITRModal = true">{{ $t("common.restore") }}- <template v-if="allowAdmin && !pitrAvailable" #tooltip>- {{ $t("database.pitr.no-available-backup") }}+ <template v-if="allowAdmin && !pitrAvailable.result" #tooltip>+ {{ pitrAvailable.message }}</template></BBTooltipButton>diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vueindex b376f22ca7..8016d24341 100644--- a/frontend/src/components/Issue/IssueDetailLayout.vue+++ b/frontend/src/components/Issue/IssueDetailLayout.vue@@ -35,6 +35,9 @@<template v-else-if="isGhostMode"><PipelineGhostFlow v-if="project" class="border-t border-b" /></template>+ <template v-else-if="isPITRMode">+ <PipelinePITRFlow v-if="project" class="border-t border-b" />+ </template><template v-else><PipelineSimpleFlow class="border-t border-b" /></template>@@ -122,6 +125,7 @@ import IssueActivityPanel from "./IssueActivityPanel.vue";import PipelineSimpleFlow from "./PipelineSimpleFlow.vue";import PipelineTenantFlow from "./PipelineTenantFlow.vue";import PipelineGhostFlow from "./PipelineGhostFlow.vue";+import PipelinePITRFlow from "./PipelinePITRFlow.vue";import TaskCheckBar from "./TaskCheckBar.vue";import type {Issue,@@ -179,6 +183,7 @@ const {project,isTenantMode,isGhostMode,+ isPITRMode,createIssue,selectedStage,selectedTask,@@ -324,6 +329,7 @@ provideIssueLogic(selectedTask,isTenantMode,isGhostMode,+ isPITRMode,isValidStage,taskStatusOfStage,activeStageOfPipeline: activeStage,diff --git a/frontend/src/components/Issue/IssueStagePanel.vue b/frontend/src/components/Issue/IssueStagePanel.vueindex 25fa50102d..ec79f1f6a3 100644--- a/frontend/src/components/Issue/IssueStagePanel.vue+++ b/frontend/src/components/Issue/IssueStagePanel.vue@@ -7,20 +7,20 @@<TaskRunTable :task-list="stage.taskList" /></template><template v-else>- <template v-for="(task, index) in stage.taskList" :key="index">+ <template v-for="(taskInStage, 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"+ v-if="stage.taskList.length > 1 && activeTask.id == taskInStage.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 }}+ {{ taskInStage.name }}</div></div>- <TaskRunTable :task-list="[task]" />+ <TaskRunTable :task-list="[taskInStage]" /></template></template></div>@@ -39,6 +39,7 @@ const {selectedTask,isGhostMode,isTenantMode,+ isPITRMode,activeTaskOfStage,} = useIssueLogic();const stage = selectedStage as Ref<Stage>;@@ -55,6 +56,7 @@ const activeTask = computed((): Task => {*/const mode = computed((): Mode => {if (isGhostMode.value) return "merged";+ if (isPITRMode.value) return "merged";if (isTenantMode.value) return "single";return "normal";});diff --git a/frontend/src/components/Issue/PipelinePITRFlow.vue b/frontend/src/components/Issue/PipelinePITRFlow.vuenew file mode 100644index 0000000000..bbe53dec0f--- /dev/null+++ b/frontend/src/components/Issue/PipelinePITRFlow.vue@@ -0,0 +1,186 @@+<template>+ <div class="divide-y">+ <PipelineStageList>+ <template #task-name-of-stage="{ stage }">+ {{ taskNameOfStage(stage) }}+ </template>+ </PipelineStageList>++ <div+ class="task-list p-2 lg:flex lg:items-center relative space-y-2 lg:space-y-0"+ >+ <template v-for="(task, i) in taskList" :key="i">+ <div+ class="task px-2 py-1 cursor-pointer border rounded lg:flex-1 flex justify-between items-center"+ :class="taskClass(task)"+ @click="onClickTask(task, i)"+ >+ <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>++ <div+ v-if="i < taskList.length - 1"+ class="hidden lg: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>+ </div>+</template>++<script lang="ts" setup>+import { computed, watchEffect } from "vue";+import type {+ Pipeline,+ Stage,+ StageCreate,+ Task,+ TaskCreate,+ Database,+} from "@/types";+import { activeTask, activeTaskInStage, taskSlug } from "@/utils";+import TaskStatusIcon from "./TaskStatusIcon.vue";+import { useDatabaseStore } from "@/store";+import PipelineStageList from "./PipelineStageList.vue";+import { useIssueLogic } from "./logic";++const databaseStore = useDatabaseStore();++const {+ create,+ issue,+ project,+ selectedStage,+ selectedTask,+ selectStageOrTask,+} = useIssueLogic();++const pipeline = computed(() => issue.value.pipeline!);++watchEffect(() => {+ if (create.value) {+ databaseStore.fetchDatabaseListByProjectId(project.value.id);+ }+});++const taskList = computed(() => {+ return selectedStage.value.taskList;+});++const databaseOfTask = (task: Task | TaskCreate): Database => {+ if (create.value) {+ return databaseStore.getDatabaseById((task as TaskCreate).databaseId!);+ }+ return (task as Task).database!;+};++const isSelectedTask = (task: Task | TaskCreate): boolean => {+ return task === selectedTask.value;+};++const isActiveTask = (task: Task | TaskCreate): boolean => {+ if (create.value) {+ return false;+ }+ task = task as Task;+ return activeTask(pipeline.value as Pipeline).id === task.id;+};++const taskNameOfStage = (stage: Stage | StageCreate) => {+ if (create.value) {+ 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, "-")}`);+ return task.name;+};++const selectedStageIdOrIndex = computed(() => {+ if (!create.value) {+ return (selectedStage.value as Stage).id;+ }+ return (pipeline.value.stageList as StageCreate[]).indexOf(+ selectedStage.value as StageCreate+ );+});++const taskClass = (task: Task | TaskCreate): string[] => {+ const classes: string[] = [];+ if (isSelectedTask(task)) classes.push("selected");+ if (isActiveTask(task)) classes.push("active");+ if (create.value) classes.push("create");+ classes.push(`status_${task.status.toLowerCase()}`);+ return classes;+};++const onClickTask = (task: Task | TaskCreate, index: number) => {+ const stageId = selectedStageIdOrIndex.value;+ const taskName = task.name;+ const taskId = create.value ? index + 1 : (task as Task).id;+ const ts = taskSlug(taskName, taskId);++ selectStageOrTask(stageId, ts);+};+</script>++<style scoped lang="postcss">+.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/logic/IssueLogic.ts b/frontend/src/components/Issue/logic/IssueLogic.tsindex e87be09685..6334257da1 100644--- a/frontend/src/components/Issue/logic/IssueLogic.ts+++ b/frontend/src/components/Issue/logic/IssueLogic.ts@@ -29,6 +29,7 @@ type IssueLogic = {// ui state logicisTenantMode: Ref<boolean>;isGhostMode: Ref<boolean>;+ isPITRMode: Ref<boolean>;isValidStage: (stage: Stage | StageCreate, index: number) => boolean;activeStageOfPipeline: (pipeline: Pipeline) => Stage;activeTaskOfPipeline: (pipeline: Pipeline) => Task;diff --git a/frontend/src/components/Issue/logic/base.ts b/frontend/src/components/Issue/logic/base.tsindex 2e61df478e..fa4284f5be 100644--- a/frontend/src/components/Issue/logic/base.ts+++ b/frontend/src/components/Issue/logic/base.ts@@ -158,6 +158,12 @@ export const useBaseIssueLogic = (params: {return issue.value.type === "bb.issue.database.schema.update.ghost";});+ const isPITRMode = computed((): boolean => {+ if (!isDev()) return false;++ return issue.value.type === "bb.issue.database.pitr";+ });+const taskStatusOfStage = (stage: Stage | StageCreate) => {if (create.value) {return stage.taskList[0].status;@@ -185,6 +191,7 @@ export const useBaseIssueLogic = (params: {project,isTenantMode,isGhostMode,+ isPITRMode,createIssue,selectedStage,selectedTask,diff --git a/frontend/src/components/Issue/logic/common.ts b/frontend/src/components/Issue/logic/common.tsindex d2ccd235d6..1d14967600 100644--- a/frontend/src/components/Issue/logic/common.ts+++ b/frontend/src/components/Issue/logic/common.ts@@ -124,7 +124,7 @@ export const useCommonLogic = () => {}// Extract statement from different types of payloads- return statementOfTask(task as Task);+ return statementOfTask(task as Task) || "";});const updateStatement = (diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 547aa9c4a2..8d9b9983ef 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -797,7 +797,8 @@"restore": "@:common.restore @:common.database","no-available-backup": "No available backup","point-in-time": "Point in time",- "help-info": "Restore the database state to a point in time. {link}."+ "help-info": "Restore the database state to a point in time. {link}.",+ "minimum-supported-engine-and-version": "{engine} >= {min_version} required"}},"repository": {diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 4ec61d97a8..2bf6337a26 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -797,7 +797,8 @@"restore": "@:common.restore@:common.database","no-available-backup": "没有可用的备份","point-in-time": "时间点",- "help-info": "将数据库的状态恢复到一个时间点。{link}。"+ "help-info": "将数据库的状态恢复到一个时间点。{link}。",+ "minimum-supported-engine-and-version": "需要 {engine} >= {min_version}"}},"repository": {diff --git a/frontend/src/plugins/pitr/index.ts b/frontend/src/plugins/pitr/index.tsindex b5abf600b7..20da3905ce 100644--- a/frontend/src/plugins/pitr/index.ts+++ b/frontend/src/plugins/pitr/index.ts@@ -1,8 +1,14 @@import { computed, Ref } from "vue";+import semverCompare from "semver/functions/compare";import { Database, IssueCreate, PITRContext, SYSTEM_BOT_ID } from "@/types";import { useBackupListByDatabaseId, useIssueStore } from "@/store";+import { useI18n } from "vue-i18n";++export const MIN_PITR_SUPPORT_MYSQL_VERSION = "5.7.0";export const usePITRLogic = (database: Ref<Database>) => {+ const { t } = useI18n();+const backupList = useBackupListByDatabaseId(computed(() => database.value.id));@@ -10,7 +16,28 @@ export const usePITRLogic = (database: Ref<Database>) => {backupList.value.filter((backup) => backup.status === "DONE"));- const pitrAvailable = computed(() => doneBackupList.value.length > 0);+ const pitrAvailable = computed((): { result: boolean; message: string } => {+ const { engine, engineVersion } = database.value.instance;+ if (+ engine === "MYSQL" &&+ semverCompare(engineVersion, MIN_PITR_SUPPORT_MYSQL_VERSION) >= 0+ ) {+ if (doneBackupList.value.length > 0) {+ return { result: true, message: "ok" };+ }+ return {+ result: false,+ message: t("database.pitr.no-available-backup"),+ };+ }+ return {+ result: false,+ message: t("database.pitr.minimum-supported-engine-and-version", {+ engine: "MySQL",+ min_version: MIN_PITR_SUPPORT_MYSQL_VERSION,+ }),+ };+ });const createPITRIssue = async (pointTimeTs: number,