Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: add rollback button to task detail (#16887)
boojack30a24e74453d
diff --git a/frontend/src/components/Plan/components/RolloutView/StageCard.vue b/frontend/src/components/Plan/components/RolloutView/StageCard.vueindex 8897a28d2f..519fe9f234 100644--- a/frontend/src/components/Plan/components/RolloutView/StageCard.vue+++ b/frontend/src/components/Plan/components/RolloutView/StageCard.vue@@ -204,6 +204,7 @@ const props = defineProps<{stage: Stage;taskStatusFilter?: Task_Status[];readonly?: boolean;+ defaultShowTasks?: boolean;}>();const router = useRouter();@@ -222,32 +223,8 @@ const isCreated = computed(() => {);});-// Determine if this is an active stage (has running tasks) or first unfinished stage-const isActiveOrFirstUnfinished = computed(() => {- // Check if stage has running tasks- const hasRunningTasks = props.stage.tasks.some(- (task) => task.status === Task_Status.RUNNING- );- if (hasRunningTasks) return true;-- // Find first stage with unfinished tasks- for (const stage of props.rollout.stages) {- const hasUnfinishedTasks = stage.tasks.some(- (task) =>- task.status !== Task_Status.DONE &&- task.status !== Task_Status.SKIPPED &&- task.status !== Task_Status.CANCELED- );- if (hasUnfinishedTasks) {- return stage.environment === props.stage.environment;- }- }-- return false;-});--// Toggle state for showing/hiding tasks - default based on stage state-const showTasks = ref(isActiveOrFirstUnfinished.value);+// Toggle state for showing/hiding tasks - default based on parent coordination+const showTasks = ref(props.defaultShowTasks || false);const filteredTasks = computed(() => {let tasks = props.stage.tasks;diff --git a/frontend/src/components/Plan/components/RolloutView/StagesView.vue b/frontend/src/components/Plan/components/RolloutView/StagesView.vueindex 87d0855a0e..54241bccfe 100644--- a/frontend/src/components/Plan/components/RolloutView/StagesView.vue+++ b/frontend/src/components/Plan/components/RolloutView/StagesView.vue@@ -13,6 +13,7 @@:stage="stage":task-status-filter="taskStatusFilter":readonly="readonly"+ :default-show-tasks="defaultShowTasksStage === stage.name"@run-tasks="(stage, tasks) => $emit('run-tasks', stage, tasks)"@create-rollout-to-stage="(stage) => $emit('create-rollout-to-stage', stage)@@ -22,15 +23,17 @@</template><script setup lang="ts">+import { computed } from "vue";import type {Stage,Task,Task_Status,Rollout,} from "@/types/proto-es/v1/rollout_service_pb";+import { Task_Status as TaskStatus } from "@/types/proto-es/v1/rollout_service_pb";import StageCard from "./StageCard.vue";-defineProps<{+const props = defineProps<{rollout: Rollout;mergedStages: Stage[];taskStatusFilter?: Task_Status[];@@ -41,4 +44,33 @@ defineEmits<{(event: "run-tasks", stage: Stage, tasks: Task[]): void;(event: "create-rollout-to-stage", stage: Stage): void;}>();++// Determine which stage should show tasks by default+const defaultShowTasksStage = computed(() => {+ // First, check if any stage has running tasks+ const stageWithRunningTasks = props.mergedStages.find((stage) =>+ stage.tasks.some((task) => task.status === TaskStatus.RUNNING)+ );+ if (stageWithRunningTasks) {+ return stageWithRunningTasks.name;+ }++ // If no running tasks, find the first stage with unfinished tasks+ const firstUnfinishedStage = props.mergedStages.find((stage) =>+ stage.tasks.some(+ (task) =>+ task.status !== TaskStatus.DONE &&+ task.status !== TaskStatus.SKIPPED &&+ task.status !== TaskStatus.CANCELED+ )+ );+ if (firstUnfinishedStage) {+ return firstUnfinishedStage.name;+ }++ // If all stages are finished, show tasks for the last stage+ return props.mergedStages.length > 0+ ? props.mergedStages[props.mergedStages.length - 1].name+ : null;+});</script>diff --git a/frontend/src/components/Plan/components/RolloutView/TaskRollbackButton.vue b/frontend/src/components/Plan/components/RolloutView/TaskRollbackButton.vuenew file mode 100644index 0000000000..324bc05842--- /dev/null+++ b/frontend/src/components/Plan/components/RolloutView/TaskRollbackButton.vue@@ -0,0 +1,56 @@+<template>+ <div>+ <NButton+ size="small"+ @click="showRollbackDrawer = true"+ icon-placement="left"+ >+ <template #icon>+ <Undo2Icon class="w-4 h-auto" />+ </template>+ {{ $t("common.rollback") }}+ </NButton>++ <TaskRunRollbackDrawer+ v-model:show="showRollbackDrawer"+ :rollout="rollout"+ :rollbackable-task-runs="rollbackableTaskRuns"+ @close="showRollbackDrawer = false"+ />+ </div>+</template>++<script setup lang="ts">+import { Undo2Icon } from "lucide-vue-next";+import { NButton } from "naive-ui";+import { computed, ref } from "vue";+import { useCurrentProjectV1 } from "@/store";+import type {+ Task,+ TaskRun,+ Rollout,+} from "@/types/proto-es/v1/rollout_service_pb";+import { databaseForTask } from "@/utils";+import TaskRunRollbackDrawer from "./TaskRunRollbackDrawer.vue";++const props = defineProps<{+ task: Task;+ taskRun: TaskRun;+ rollout: Rollout;+}>();++const { project } = useCurrentProjectV1();++const showRollbackDrawer = ref(false);++// Prepare rollbackable task run data for the drawer+const rollbackableTaskRuns = computed(() => {+ return [+ {+ task: props.task,+ taskRun: props.taskRun,+ database: databaseForTask(project.value, props.task),+ },+ ];+});+</script>diff --git a/frontend/src/components/Plan/components/RolloutView/TaskRunRollbackDrawer.vue b/frontend/src/components/Plan/components/RolloutView/TaskRunRollbackDrawer.vueindex e87d0c608f..61c92badf3 100644--- a/frontend/src/components/Plan/components/RolloutView/TaskRunRollbackDrawer.vue+++ b/frontend/src/components/Plan/components/RolloutView/TaskRunRollbackDrawer.vue@@ -36,13 +36,29 @@class="space-y-2"><DatabaseDisplay :database="preview.task.target" />- <MonacoEditor- v-if="preview.statement"- class="border rounded-[3px] text-sm overflow-clip"- :content="preview.statement"- :readonly="true"- :auto-height="{ min: 100, max: 200 }"- />+ <template v-if="!isUndefined(preview.statement)">+ <MonacoEditor+ v-if="preview.statement"+ class="border rounded-[3px] text-sm overflow-clip"+ :content="preview.statement"+ :readonly="true"+ :auto-height="{ min: 100, max: 200 }"+ />+ <!-- Empty generated statement placeholder -->+ <div+ v-else+ class="flex items-center justify-center p-8 border rounded-[3px] bg-gray-50"+ >+ <div class="text-center space-y-2">+ <DatabaseBackupIcon+ class="w-6 h-6 mx-auto text-gray-400"+ />+ <p class="text-sm text-gray-500">+ {{ $t("task-run.rollback.no-statement-generated") }}+ </p>+ </div>+ </div>+ </template><divv-else-if="preview.error"class="p-3 border border-red-200 bg-red-50 rounded text-sm text-red-600"@@ -103,9 +119,11 @@<script setup lang="ts">import { create } from "@bufbuild/protobuf";import { createContextValues } from "@connectrpc/connect";+import { isUndefined } from "lodash-es";+import { DatabaseBackupIcon } from "lucide-vue-next";import { NSteps, NStep, NButton, NAlert, NSkeleton } from "naive-ui";import { v4 as uuidv4 } from "uuid";-import { computed, reactive, ref, watch } from "vue";+import { computed, reactive, ref, watch, nextTick } from "vue";import { useRouter } from "vue-router";import { MonacoEditor } from "@/components/MonacoEditor";import DatabaseDisplay from "@/components/Plan/components/common/DatabaseDisplay.vue";@@ -205,7 +223,8 @@ const isTaskSelectable = (task: Task): boolean => {const canCreateRollback = computed(() => {return (rollbackPreviews.value.length > 0 &&- rollbackPreviews.value.every((p) => p.statement && !p.error) &&+ rollbackPreviews.value.every((p) => !p.error) &&+ rollbackPreviews.value.some((p) => p.statement) && // At least one non-empty statementhasProjectPermissionV2(project.value, "bb.plans.create"));});@@ -346,6 +365,14 @@ const resetState = () => {watch(show, (newValue) => {if (newValue) {resetState();+ // Auto-select and advance to step 2 if there's only one task+ if (rollbackableTasks.value.length === 1) {+ selectedTasks.value = [rollbackableTasks.value[0]];+ // Use nextTick to ensure state is properly initialized before advancing+ nextTick(() => {+ handleNextStep();+ });+ }}});</script>diff --git a/frontend/src/components/Plan/components/RolloutView/TaskView.vue b/frontend/src/components/Plan/components/RolloutView/TaskView.vueindex bd43a64fc7..28873a8b33 100644--- a/frontend/src/components/Plan/components/RolloutView/TaskView.vue+++ b/frontend/src/components/Plan/components/RolloutView/TaskView.vue@@ -26,14 +26,23 @@</div></div>- <!-- Task Status Actions -->- <TaskStatusActions- :task="task"- :task-runs="taskRuns"- :rollout="rollout"- :readonly="readonly"- @action-confirmed="handleTaskActionConfirmed"- />+ <div class="flex justify-end">+ <!-- Task Status Actions -->+ <TaskStatusActions+ :task="task"+ :task-runs="taskRuns"+ :rollout="rollout"+ :readonly="readonly"+ @action-confirmed="handleTaskActionConfirmed"+ />+ <!-- Rollback entry -->+ <TaskRollbackButton+ v-if="rollbackableTaskRun"+ :task="task"+ :task-run="rollbackableTaskRun"+ :rollout="rollout"+ />+ </div></div></div>@@ -79,29 +88,30 @@</template><script setup lang="ts">-import { create } from "@bufbuild/protobuf";-import { isEqual, sortBy } from "lodash-es";+import { head } from "lodash-es";import { ChevronRightIcon } from "lucide-vue-next";import { NTag, NTooltip } from "naive-ui";-import { computed, ref, watchEffect } from "vue";+import { computed, watchEffect } from "vue";import { semanticTaskType } from "@/components/IssueV1";import TaskRunDetail from "@/components/IssueV1/components/TaskRunSection/TaskRunDetail.vue";import { MonacoEditor } from "@/components/MonacoEditor";import TaskStatus from "@/components/Rollout/kits/TaskStatus.vue";import { InstanceV1EngineIcon, CopyButton } from "@/components/v2";-import { rolloutServiceClientConnect } from "@/grpcweb";-import { useCurrentProjectV1, useSheetV1Store } from "@/store";-import { getDateForPbTimestampProtoEs, unknownTask } from "@/types";-import type { TaskRun } from "@/types/proto-es/v1/rollout_service_pb";-import { ListTaskRunsRequestSchema } from "@/types/proto-es/v1/rollout_service_pb";+import {+ taskRunNamePrefix,+ useCurrentProjectV1,+ useSheetV1Store,+} from "@/store";+import { unknownTask } from "@/types";+import { TaskRun_Status } from "@/types/proto-es/v1/rollout_service_pb";import { databaseForTask } from "@/utils";import {extractSchemaVersionFromTask,getSheetStatement,sheetNameOfTaskV1,- isValidTaskName,} from "@/utils";import { usePlanContextWithRollout } from "../../logic";+import TaskRollbackButton from "./TaskRollbackButton.vue";import TaskRunTable from "./TaskRunTable.vue";import TaskStatusActions from "./TaskStatusActions.vue";@@ -112,11 +122,14 @@ const props = defineProps<{}>();const { project } = useCurrentProjectV1();-const { rollout, readonly, events } = usePlanContextWithRollout();+const {+ rollout,+ taskRuns: allTaskRuns,+ readonly,+ events,+} = usePlanContextWithRollout();const sheetStore = useSheetV1Store();-const taskRunsRef = ref<TaskRun[]>([]);-// Get the task - either from props or from fetched rolloutconst task = computed(() => {return (rollout.value.stages@@ -125,6 +138,25 @@ const task = computed(() => {);});+const taskRuns = computed(() => {+ return allTaskRuns.value.filter((run) =>+ run.name.startsWith(`${task.value.name}/${taskRunNamePrefix}`)+ );+});++const latestTaskRun = computed(() => head(taskRuns.value));++const rollbackableTaskRun = computed(() => {+ if (+ latestTaskRun.value &&+ latestTaskRun.value.status === TaskRun_Status.DONE &&+ latestTaskRun.value.priorBackupDetail !== undefined+ ) {+ return latestTaskRun.value;+ }+ return undefined;+});+// Task basic infoconst database = computed(() => databaseForTask(project.value, task.value));const schemaVersion = computed(() => extractSchemaVersionFromTask(task.value));@@ -138,30 +170,7 @@ const statement = computed(() => {return "";});-// Fetch task runs-watchEffect(async () => {- if (!isValidTaskName(task.value.name)) {- return;- }-- try {- const request = create(ListTaskRunsRequestSchema, {- parent: task.value.name,- });- const response = await rolloutServiceClientConnect.listTaskRuns(request);- const taskRuns = response.taskRuns;- const sorted = sortBy(taskRuns, (t) =>- getDateForPbTimestampProtoEs(t.createTime)- ).reverse();- if (!isEqual(sorted, taskRunsRef.value)) {- taskRunsRef.value = sorted;- }- } catch (error) {- console.error("Failed to fetch task runs:", error);- }-});--// Fetch sheet when task changes+// Prepare sheet of the task.watchEffect(async () => {const sheetName = sheetNameOfTaskV1(task.value);if (sheetName) {@@ -169,28 +178,8 @@ watchEffect(async () => {}});-// Task run info-const taskRuns = computed(() => taskRunsRef.value);-const latestTaskRun = computed(() => taskRuns.value[0]);-// Handle task action completion to refresh dataconst handleTaskActionConfirmed = async () => {- // Refresh task runs after action- if (isValidTaskName(task.value.name)) {- try {- const request = create(ListTaskRunsRequestSchema, {- parent: task.value.name,- });- const response = await rolloutServiceClientConnect.listTaskRuns(request);- const taskRuns = response.taskRuns;- const sorted = sortBy(taskRuns, (t) =>- getDateForPbTimestampProtoEs(t.createTime)- ).reverse();- taskRunsRef.value = sorted;- } catch (error) {- console.error("Failed to refresh task runs:", error);- }- }events.emit("status-changed", { eager: true });};</script>diff --git a/frontend/src/components/Plan/components/SpecDetailView/TargetListSection.vue b/frontend/src/components/Plan/components/SpecDetailView/TargetListSection.vueindex 3e334532f1..0b81ea82ea 100644--- a/frontend/src/components/Plan/components/SpecDetailView/TargetListSection.vue+++ b/frontend/src/components/Plan/components/SpecDetailView/TargetListSection.vue@@ -64,7 +64,7 @@</span><div class="flex items-center gap-x-1 min-w-0 text-sm"><NEllipsis :line-clamp="1">- <span class="font-medium">{{ item.name }}</span>+ {{ item.name }}</NEllipsis></div><divdiff --git a/frontend/src/components/Plan/logic/poller/poller.ts b/frontend/src/components/Plan/logic/poller/poller.tsindex 352c21c280..a452c70456 100644--- a/frontend/src/components/Plan/logic/poller/poller.ts+++ b/frontend/src/components/Plan/logic/poller/poller.ts@@ -27,17 +27,10 @@ import {refreshPlanCheckRuns,refreshRollout,refreshIssue,- refreshIssueComments,refreshTaskRuns,} from "./utils";-type ResourceType =- | "plan"- | "planCheckRuns"- | "issue"- | "issueComments"- | "rollout"- | "taskRuns";+type ResourceType = "plan" | "planCheckRuns" | "issue" | "rollout" | "taskRuns";// Progressive polling configuration for the resource poller// This configuration implements an exponential backoff strategy to reduce server load@@ -113,7 +106,7 @@ export const provideResourcePoller = () => {// Issue-specific pagesif (includes([PROJECT_V1_ROUTE_ISSUE_DETAIL_V1], routeName)) {- return ["issue", "issueComments"];+ return ["issue"];}// Rollout-specific pages@@ -131,14 +124,7 @@ export const provideResourcePoller = () => {}// Default to polling all resources- return [- "plan",- "planCheckRuns",- "issue",- "issueComments",- "rollout",- "taskRuns",- ];+ return ["plan", "planCheckRuns", "issue", "rollout", "taskRuns"];});const resourcesToPolled = computed<ResourceType[]>(() => {@@ -164,11 +150,6 @@ export const provideResourcePoller = () => {await refreshIssue(issue as any);};- const refreshIssueCommentsOnly = async () => {- if (!issue?.value) return;- await refreshIssueComments(issue.value);- };-const refreshRolloutOnly = async () => {if (!plan.value?.rollout || !rollout) return;await refreshRollout(plan.value.rollout, project.value, rollout);@@ -203,9 +184,6 @@ export const provideResourcePoller = () => {if (activeResources.includes("issue") && issue?.value) {refreshPromises.push(refreshIssue(issue as any));}- if (activeResources.includes("issueComments") && issue?.value) {- refreshPromises.push(refreshIssueComments(issue.value));- }if (activeResources.includes("rollout") &&plan.value?.rollout &&@@ -297,8 +275,6 @@ export const provideResourcePoller = () => {refreshPromises.push(refreshPlanCheckRunsOnly());if (activeResources.includes("issue"))refreshPromises.push(refreshIssueOnly());- if (activeResources.includes("issueComments"))- refreshPromises.push(refreshIssueCommentsOnly());if (activeResources.includes("rollout"))refreshPromises.push(refreshRolloutOnly());if (activeResources.includes("taskRuns"))@@ -332,7 +308,7 @@ export const provideResourcePoller = () => {});events.on("perform-issue-review-action", async () => {- await Promise.all([refreshIssueOnly(), refreshIssueCommentsOnly()]);+ await Promise.all([refreshIssueOnly()]);events.emit("status-changed", { eager: true });});diff --git a/frontend/src/components/Plan/logic/poller/utils.ts b/frontend/src/components/Plan/logic/poller/utils.tsindex f412a8f28b..5f67da4203 100644--- a/frontend/src/components/Plan/logic/poller/utils.ts+++ b/frontend/src/components/Plan/logic/poller/utils.ts@@ -5,10 +5,8 @@ import {planServiceClientConnect,rolloutServiceClientConnect,} from "@/grpcweb";-import { useIssueCommentStore } from "@/store";import type { ComposedProject } from "@/types";import { GetIssueRequestSchema } from "@/types/proto-es/v1/issue_service_pb";-import { ListIssueCommentsRequestSchema } from "@/types/proto-es/v1/issue_service_pb";import type { Issue } from "@/types/proto-es/v1/issue_service_pb";import {GetPlanRequestSchema,@@ -72,16 +70,6 @@ export const refreshIssue = async (issue: Ref<Issue>): Promise<void> => {issue.value = newIssue;};-export const refreshIssueComments = async (issue: Issue): Promise<void> => {- const issueCommentStore = useIssueCommentStore();- await issueCommentStore.listIssueComments(- create(ListIssueCommentsRequestSchema, {- parent: issue.name,- pageSize: 1000,- })- );-};-export const refreshTaskRuns = async (rollout: Rollout,project: ComposedProject,diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 36f44d17bf..3d4554cd05 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -327,7 +327,8 @@"preview-statement": {"self": "Preview Statement","description": "Bytebase generates a rollback statement based on the task run. You can review the statement before executing the rollback."- }+ },+ "no-statement-generated": "No rollback statement generated"}},"banner": {diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 3b34399584..3d4092564f 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -327,7 +327,8 @@"preview-statement": {"self": "Declaración de vista previa","description": "Bytebase genera una sentencia de reversión según la ejecución de la tarea. Puede revisar la sentencia antes de ejecutar la reversión."- }+ },+ "no-statement-generated": "No se generó ninguna declaración de reversión"}},"banner": {diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 04de4983b3..273aec2181 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -327,7 +327,8 @@"preview-statement": {"self": "プレビューステートメント","description": "Bytebaseはタスク実行に基づいてロールバックステートメントを生成します。ロールバックを実行する前にステートメントを確認できます。"- }+ },+ "no-statement-generated": "ロールバックステートメントは生成されません"}},"banner": {diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex 9e4227601b..9b15f558b5 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -327,7 +327,8 @@"preview-statement": {"self": "Xem trước tuyên bố","description": "Bytebase tạo ra một câu lệnh khôi phục dựa trên tác vụ đang chạy. Bạn có thể xem lại câu lệnh này trước khi thực hiện khôi phục."- }+ },+ "no-statement-generated": "Không có câu lệnh khôi phục nào được tạo ra"}},"banner": {diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 76e7c863d4..f3d9425874 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -327,7 +327,8 @@"preview-statement": {"self": "预览语句","description": "Bytebase 根据任务运行情况生成回滚语句,您可以在执行回滚前查看该语句。"- }+ },+ "no-statement-generated": "生成的回滚语句为空"}},"banner": {@@ -1058,10 +1059,10 @@"approval": {"rejected-title": "工单被退回","pending-title": "工单待审批",- "rejected-description": "此工单已被审批者退回。确认并勾选强制执行才能继续。",- "pending-description": "此工单正在等待审批。确认并勾选强制执行才能继续。",- "rejected-error": "此工单已被退回。请确认并勾选强制执行才能继续。",- "pending-error": "此工单正在等待审批。请确认并勾选强制执行才能继续。"+ "rejected-description": "此工单已被审批者退回。确认并勾选强制运行才能继续。",+ "pending-description": "此工单正在等待审批。确认并勾选强制运行才能继续。",+ "rejected-error": "此工单已被退回。请确认并勾选强制运行才能继续。",+ "pending-error": "此工单正在等待审批。请确认并勾选强制运行才能继续。"},"new-layout": "使用新版 CI/CD 页面"},@@ -1136,7 +1137,7 @@},"rollout": {"rollouts": "发布任务",- "force-rollout": "强制执行",+ "force-rollout": "强制运行","stage": {"self": "阶段 | 阶段","start-stage": "开始该阶段",@@ -1148,7 +1149,7 @@"message": {"pervious-stages-incomplete": {"title": "前置阶段尚未完成",- "description": "存在未完成的前置阶段。请确认并勾选强制执行才能继续。"+ "description": "存在未完成的前置阶段。请确认并勾选强制运行才能继续。"}}},