Skip to content

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

feat(frontend): rollback SQL UI (#4714)

Liu Ji3fc192f17630
diff --git a/frontend/src/components/Issue/IssueRollbackButton.vue b/frontend/src/components/Issue/IssueRollbackButton.vue
deleted file mode 100644
index b6cc581dba..0000000000
--- a/frontend/src/components/Issue/IssueRollbackButton.vue
+++ /dev/null
@@ -1,198 +0,0 @@
-<template>
- <button
- v-if="showRollbackButton"
- :disabled="!allowRollback || state.buttonState === ButtonState.LOADING"
- type="button"
- class="mt-0.5 px-3 inline-flex items-center gap-x-2 border border-control-border rounded-sm text-control bg-control-bg hover:bg-control-bg-hover text-sm leading-5 font-normal focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-2 relative disabled:cursor-not-allowed disabled:text-gray-400 disabled:hover:bg-control-bg"
- @click="tryRollbackTask"
- >
- {{ $t("common.rollback") }}
- <template v-if="state.buttonState === ButtonState.LOADING">
- <BBSpin class="w-4 h-4 -mr-1.5" />
- </template>
- </button>
-</template>
-
-<script lang="ts" setup>
-import { computed, reactive } from "vue";
-import { useRouter } from "vue-router";
-import dayjs from "dayjs";
-
-import type {
- ActivityCreate,
- Issue,
- IssueCreate,
- RollbackContext,
- Task,
- TaskDatabaseDataUpdatePayload,
-} from "@/types";
-import { useIssueLogic } from "./logic";
-import { useActivityStore, useCurrentUser, useIssueStore } from "@/store";
-import { hasProjectPermission, hasWorkspacePermission, isDev } from "@/utils";
-
-enum ButtonState {
- DEFAULT,
- LOADING,
- GENERATED,
-}
-
-type LocalState = {
- buttonState: ButtonState;
- rollbackIssue: Issue | undefined;
-};
-
-const state = reactive<LocalState>({
- buttonState: ButtonState.DEFAULT,
- rollbackIssue: undefined,
-});
-
-const router = useRouter();
-const issueStore = useIssueStore();
-const currentUser = useCurrentUser();
-
-const { issue, create, selectedTask } = useIssueLogic();
-
-const showRollbackButton = computed(() => {
- if (!isDev()) return false;
-
- if (create.value) return false;
-
- const issueEntity = issue.value as Issue;
- const task = selectedTask.value as Task;
-
- return (
- issueEntity.type === "bb.issue.database.data.update" &&
- task.type === "bb.task.database.data.update" &&
- task.status === "DONE" &&
- task.database?.instance.engine === "MYSQL"
- );
-});
-
-const allowRollback = computed(() => {
- if (!showRollbackButton.value) return false;
-
- const issueEntity = issue.value as Issue;
- const user = currentUser.value;
-
- if (user.id === issueEntity.creator.id) {
- // Allowed to the issue creator
- return true;
- }
-
- if (user.id === issueEntity.assignee.id) {
- // Allowed to the issue assignee
- return true;
- }
-
- const memberInProject = issueEntity.project.memberList.find(
- (member) => member.principal.id === user.id
- );
- if (
- memberInProject?.role &&
- hasProjectPermission(
- "bb.permission.project.admin-database",
- memberInProject.role
- )
- ) {
- // Allowed to the project owner
- return true;
- }
-
- if (
- hasWorkspacePermission("bb.permission.workspace.manage-issue", user.role)
- ) {
- // Allowed to DBAs and workspace owners
- return true;
- }
- return false;
-});
-
-const tryRollbackTask = async () => {
- if (!showRollbackButton.value) return;
-
- const navigateToRollbackIssue = () => {
- if (!state.rollbackIssue) return;
- router.push(`/issue/${state.rollbackIssue.id}`);
- };
-
- if (state.buttonState === ButtonState.GENERATED && state.rollbackIssue) {
- return navigateToRollbackIssue();
- }
-
- try {
- state.buttonState = ButtonState.LOADING;
-
- const issueEntity = issue.value as Issue;
- const task = selectedTask.value as Task;
-
- const rollbackContext: RollbackContext = {
- issueId: issueEntity.id,
- taskIdList: [task.id],
- };
-
- const datetime = `${dayjs(issueEntity.createdTs * 1000).format(
- "MM-DD HH:mm:ss"
- )}`;
- const tz = `UTC${dayjs().format("ZZ")}`;
-
- const issueName = [
- `[${task.database!.name}]`,
- `Rollback ${task.name}`,
- `in #${issueEntity.id}`,
- `@${datetime} ${tz}`,
- ].join(" ");
-
- const description = [
- `The original SQL statement:\n${
- (task.payload as TaskDatabaseDataUpdatePayload).statement
- }`,
- ].join("\n");
-
- const issueCreate: IssueCreate = {
- type: "bb.issue.database.rollback",
- projectId: issueEntity.project.id,
- name: issueName,
- description,
- payload: {},
- // Use the same assignee as the original issue
- assigneeId: issueEntity.assignee.id,
- createContext: rollbackContext,
- };
-
- const createdIssue = await issueStore.createIssue(issueCreate);
- state.rollbackIssue = createdIssue;
-
- state.buttonState = ButtonState.GENERATED;
-
- await createRollbackCommentActivity(task, issueEntity, createdIssue);
-
- navigateToRollbackIssue();
- } catch {
- state.buttonState = ButtonState.DEFAULT;
- }
-};
-
-const createRollbackCommentActivity = async (
- task: Task,
- issue: Issue,
- newIssue: Issue
-) => {
- const comment = [
- "Rollback task",
- `[${task.name}]`,
- `in issue #${newIssue.id}`,
- ].join(" ");
-
- const createActivity: ActivityCreate = {
- type: "bb.issue.comment.create",
- containerId: issue.id,
- comment,
- };
- try {
- await useActivityStore().createActivity(createActivity);
- } catch {
- // do nothing
- // failing to comment to won't be too bad
- }
-};
-</script>
diff --git a/frontend/src/components/Issue/IssueSidebar.vue b/frontend/src/components/Issue/IssueSidebar.vue
index 6d4f7e9572..48dbe3ef7d 100644
--- a/frontend/src/components/Issue/IssueSidebar.vue
+++ b/frontend/src/components/Issue/IssueSidebar.vue
@@ -1,7 +1,7 @@
<template>
<aside class="pr-0.5">
<h2 class="sr-only">Details</h2>
- <div class="grid gap-y-6 gap-x-6 grid-cols-3">
+ <div class="grid gap-y-6 gap-x-1 grid-cols-3">
<template v-if="!create">
<h2 class="textlabel flex items-center col-span-1 col-start-1">
{{ $t("common.status") }}
@@ -72,7 +72,7 @@
</template>
</div>
<div
- class="mt-6 border-t border-block-border pt-6 grid gap-y-6 gap-x-6 grid-cols-3"
+ class="mt-6 border-t border-block-border pt-6 grid gap-y-6 gap-x-1 grid-cols-3"
>
<template v-if="showStageSelect">
<h2 class="textlabel flex items-center col-span-1 col-start-1">
@@ -101,6 +101,8 @@
</div>
</template>
+ <TaskRollbackView />
+
<template v-if="!isTenantMode">
<!--
earliest-allowed-time is disabled in tenant mode for now
@@ -211,7 +213,7 @@
</template>
</div>
<div
- class="mt-6 border-t border-block-border pt-6 grid gap-y-6 gap-x-6 grid-cols-3"
+ class="mt-6 border-t border-block-border pt-6 grid gap-y-6 gap-x-1 grid-cols-3"
>
<h2 class="textlabel flex items-center col-span-1 col-start-1">
{{ $t("common.project") }}
@@ -284,6 +286,7 @@ import StageSelect from "./StageSelect.vue";
import TaskSelect from "./TaskSelect.vue";
import IssueStatusIcon from "./IssueStatusIcon.vue";
import IssueSubscriberPanel from "./IssueSubscriberPanel.vue";
+import TaskRollbackView from "./rollback/TaskRollbackView.vue";
import InstanceEngineIcon from "../InstanceEngineIcon.vue";
import PrincipalAvatar from "../PrincipalAvatar.vue";
import MemberSelect from "../MemberSelect.vue";
diff --git a/frontend/src/components/Issue/IssueTaskStatementPanel.vue b/frontend/src/components/Issue/IssueTaskStatementPanel.vue
index f697010597..71615f7384 100644
--- a/frontend/src/components/Issue/IssueTaskStatementPanel.vue
+++ b/frontend/src/components/Issue/IssueTaskStatementPanel.vue
@@ -124,8 +124,6 @@
<heroicons-solid:pencil class="h-5 w-5" />
</button>
</template>
-
- <IssueRollbackButton />
</div>
</div>
<label class="sr-only">{{ $t("common.sql-statement") }}</label>
@@ -212,7 +210,6 @@ import type {
import { baseDirectoryWebUrl, UNKNOWN_ID } from "@/types";
import { TableMetadata } from "@/types/proto/store/database";
import MonacoEditor from "../MonacoEditor/MonacoEditor.vue";
-import IssueRollbackButton from "./IssueRollbackButton.vue";
import { isUndefined } from "lodash-es";
import { isTaskTriggeredByVCS, useInstanceEditorLanguage } from "@/utils";
import { useSQLAdviceMarkers } from "./logic/useSQLAdviceMarkers";
diff --git a/frontend/src/components/Issue/logic/common.ts b/frontend/src/components/Issue/logic/common.ts
index f414fcc67e..1ac0c2ed04 100644
--- a/frontend/src/components/Issue/logic/common.ts
+++ b/frontend/src/components/Issue/logic/common.ts
@@ -204,6 +204,7 @@ export const useCommonLogic = () => {
statement: maybeFormatStatementOnSave(taskCreate.statement, db),
sheetId: taskCreate.sheetId,
earliestAllowedTs: taskCreate.earliestAllowedTs,
+ rollbackEnabled: taskCreate.rollbackEnabled,
};
// If task already has sheet id, we do not need to save statement.
if (!isUndefined(taskCreate.sheetId)) {
diff --git a/frontend/src/components/Issue/rollback/RollbackStatus.vue b/frontend/src/components/Issue/rollback/RollbackStatus.vue
new file mode 100644
index 0000000000..75ce9d8e52
--- /dev/null
+++ b/frontend/src/components/Issue/rollback/RollbackStatus.vue
@@ -0,0 +1,179 @@
+<template>
+ <div class="text-sm font-medium">
+ <template v-if="!payload?.rollbackEnabled">
+ <button
+ :disabled="!allowRollback"
+ class="btn-normal !px-3 !py-1"
+ @click="toggleRollback(true)"
+ >
+ {{ $t("task.rollback.log") }}
+ </button>
+ </template>
+ <template v-else>
+ <template v-if="payload?.rollbackError">
+ <div class="tooltip-wrapper">
+ <NTooltip>
+ <template #trigger>
+ <span class="text-error">{{ $t("task.rollback.failed") }}</span>
+ </template>
+
+ <div class="max-w-[20rem]">{{ payload.rollbackError }}</div>
+ </NTooltip>
+ </div>
+ </template>
+ <template v-else-if="payload?.rollbackStatement">
+ <button
+ :disabled="!allowRollback"
+ class="btn-normal !px-3 !py-1"
+ @click="tryRollbackTask"
+ >
+ {{ $t("task.rollback.preview-rollback") }}
+ </button>
+ </template>
+ <template v-else>
+ <div
+ class="select-none inline-flex items-center border border-control-border rounded-md text-control bg-white text-sm leading-5 font-medium focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-2"
+ :class="[
+ !allowRollback && 'cursor-not-allowed bg-control-bg opacity-50 ',
+ ]"
+ >
+ <span class="pl-3 pr-0.5">{{ $t("task.rollback.logging") }}</span>
+ <span
+ class="h-[28px] px-1.5 flex items-center rounded-r-md hover:bg-control-bg-hover cursor-pointer"
+ :class="[!allowRollback && 'pointer-events-none']"
+ @click="toggleRollback(false)"
+ >
+ <heroicons-outline:x-mark class="w-3 h-3" />
+ </span>
+ </div>
+ </template>
+ </template>
+ </div>
+</template>
+<script lang="ts" setup>
+import { computed, reactive, type Ref } from "vue";
+import { NTooltip } from "naive-ui";
+import dayjs from "dayjs";
+
+import type {
+ ActivityCreate,
+ Issue,
+ IssueCreate,
+ RollbackContext,
+ Task,
+ TaskDatabaseDataUpdatePayload,
+} from "@/types";
+import { useIssueLogic } from "../logic";
+import { useRouter } from "vue-router";
+import { useActivityStore, useIssueStore } from "@/store";
+import { absolutifyLink, buildIssueLinkWithTask } from "@/utils";
+import { useRollbackLogic } from "./common";
+
+type LocalState = {
+ loading: boolean;
+ rollbackIssue: Issue | undefined;
+};
+
+const router = useRouter();
+const issueStore = useIssueStore();
+
+const context = useIssueLogic();
+const { allowRollback, toggleRollback } = useRollbackLogic();
+
+const issue = context.issue as Ref<Issue>;
+const task = context.selectedTask as Ref<Task>;
+const payload = computed(
+ () => task.value.payload as TaskDatabaseDataUpdatePayload | undefined
+);
+
+const state = reactive<LocalState>({
+ loading: false,
+ rollbackIssue: undefined,
+});
+
+const tryRollbackTask = async () => {
+ const navigateToRollbackIssue = () => {
+ if (!state.rollbackIssue) return;
+ router.push(`/issue/${state.rollbackIssue.id}`);
+ };
+
+ if (state.rollbackIssue) {
+ return navigateToRollbackIssue();
+ }
+
+ try {
+ state.loading = true;
+
+ const rollbackContext: RollbackContext = {
+ issueId: issue.value.id,
+ taskIdList: [task.value.id],
+ };
+
+ const datetime = `${dayjs(issue.value.createdTs * 1000).format(
+ "MM-DD HH:mm:ss"
+ )}`;
+ const tz = `UTC${dayjs().format("ZZ")}`;
+
+ const issueName = [
+ `[${task.value.database!.name}]`,
+ `Rollback ${task.value.name}`,
+ `in #${issue.value.id}`,
+ `@${datetime} ${tz}`,
+ ].join(" ");
+
+ const originalIssueTaskLink = buildIssueLinkWithTask(
+ issue.value,
+ task.value,
+ true /* Keep the URL short and clean */
+ );
+ const description = [
+ `The original task: ${absolutifyLink(originalIssueTaskLink)}`,
+ `The original SQL statement: ${payload.value!.statement}`,
+ ].join("\n");
+
+ const issueCreate: IssueCreate = {
+ type: "bb.issue.database.rollback",
+ projectId: issue.value.project.id,
+ name: issueName,
+ description,
+ payload: {},
+ // Use the same assignee as the original issue
+ assigneeId: issue.value.assignee.id,
+ createContext: rollbackContext,
+ };
+
+ const createdIssue = await issueStore.createIssue(issueCreate);
+ state.rollbackIssue = createdIssue;
+
+ await createRollbackCommentActivity(task.value, issue.value, createdIssue);
+
+ navigateToRollbackIssue();
+ } finally {
+ state.loading = false;
+ }
+};
+
+const createRollbackCommentActivity = async (
+ task: Task,
+ issue: Issue,
+ newIssue: Issue
+) => {
+ const comment = [
+ "Rollback task",
+ `[${task.name}]`,
+ `in issue #${newIssue.id}`,
+ ].join(" ");
+
+ const createActivity: ActivityCreate = {
+ type: "bb.issue.comment.create",
+ containerId: issue.id,
+ comment,
+ };
+ try {
+ await useActivityStore().createActivity(createActivity);
+ } catch {
+ // do nothing
+ // failing to comment to won't be too bad
+ }
+};
+</script>
diff --git a/frontend/src/components/Issue/rollback/RollbackSwitch.vue b/frontend/src/components/Issue/rollback/RollbackSwitch.vue
new file mode 100644
index 0000000000..205281e2f3
--- /dev/null
+++ b/frontend/src/components/Issue/rollback/RollbackSwitch.vue
@@ -0,0 +1,14 @@
+<template>
+ <BBCheckbox
+ :disabled="!allowRollback"
+ :value="rollbackEnabled"
+ @toggle="toggleRollback"
+ />
+</template>
+
+<script lang="ts" setup>
+import { BBCheckbox } from "@/bbkit";
+import { useRollbackLogic } from "./common";
+
+const { allowRollback, rollbackEnabled, toggleRollback } = useRollbackLogic();
+</script>
diff --git a/frontend/src/components/Issue/rollback/TaskRollbackView.vue b/frontend/src/components/Issue/rollback/TaskRollbackView.vue
new file mode 100644
index 0000000000..f9c874c4be
--- /dev/null
+++ b/frontend/src/components/Issue/rollback/TaskRollbackView.vue
@@ -0,0 +1,22 @@
+<template>
+ <div v-if="rollbackUIType !== 'NONE'" class="contents">
+ <h2 class="textlabel flex items-center">
+ <span class="mr-1">{{ $t("task.rollback.sql-rollback") }}</span>
+ <!-- TODO(Jim): bring this icon back when user doc is ready -->
+ <!-- <heroicons-outline:question-mark-circle class="h-4 w-4" /> -->
+ </h2>
+
+ <div class="col-span-2">
+ <RollbackSwitch v-if="rollbackUIType === 'SWITCH'" />
+ <RollbackStatus v-if="rollbackUIType === 'FULL'" />
+ </div>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import RollbackSwitch from "./RollbackSwitch.vue";
+import RollbackStatus from "./RollbackStatus.vue";
+import { useRollbackLogic } from "./common";
+
+const { rollbackUIType } = useRollbackLogic();
+</script>
diff --git a/frontend/src/components/Issue/rollback/common.ts b/frontend/src/components/Issue/rollback/common.ts
new file mode 100644
index 0000000000..946535f9f7
--- /dev/null
+++ b/frontend/src/components/Issue/rollback/common.ts
@@ -0,0 +1,182 @@
+import { computed } from "vue";
+import { head } from "lodash-es";
+
+import type {
+ Database,
+ Issue,
+ IssueCreate,
+ MigrationContext,
+ Task,
+ TaskCreate,
+ TaskDatabaseDataUpdatePayload,
+} from "@/types";
+import {
+ hasProjectPermission,
+ hasWorkspacePermission,
+ isTaskCreate,
+ isTaskSkipped,
+ semverCompare,
+} from "@/utils";
+import { useIssueLogic } from "../logic";
+import { useCurrentUser, useDatabaseStore } from "@/store";
+
+const MIN_ROLLBACK_SQL_MYSQL_VERSION = "5.7.0";
+
+export type RollbackUIType =
+ | "SWITCH" // Show a simple checkbox to turn on/off rollback
+ | "FULL" // Show featured rollback status
+ | "NONE"; // Nothing
+
+export const useRollbackLogic = () => {
+ const currentUser = useCurrentUser();
+ const context = useIssueLogic();
+ const {
+ create,
+ issue,
+ isTenantMode,
+ selectedTask: task,
+ patchTask,
+ } = context;
+
+ // Decide with type of UI should be displayed.
+ const rollbackUIType = computed((): RollbackUIType => {
+ if (issue.value.type !== "bb.issue.database.data.update") {
+ return "NONE";
+ }
+ if (task.value.type !== "bb.task.database.data.update") {
+ return "NONE";
+ }
+ const database = databaseOfTask(task.value);
+ const { engine, engineVersion } = database.instance;
+ if (engine !== "MYSQL") {
+ return "NONE";
+ }
+ if (!semverCompare(engineVersion, MIN_ROLLBACK_SQL_MYSQL_VERSION, "gte")) {
+ return "NONE";
+ }
+ if (create.value) {
+ return "SWITCH";
+ }
+ const taskEntity = task.value as Task;
+ if (taskEntity.status === "DONE") {
+ if (isTaskSkipped(taskEntity)) {
+ // Rollback is not available for skipped tasks.
+ return "NONE";
+ }
+ return "FULL";
+ }
+ if (taskEntity.status === "CANCELED") {
+ return "NONE";
+ }
+
+ return "SWITCH";
+ });
+
+ // Decide whether current user can operate.
+ const allowRollback = computed((): boolean => {
+ if (rollbackUIType.value === "NONE") {
+ return false;
+ }
+
+ if (create.value) {
+ return true;
+ }
+
+ const issueEntity = issue.value as Issue;
+ const user = currentUser.value;
+
+ if (user.id === issueEntity.creator.id) {
+ // Allowed to the issue creator
+ return true;
+ }
+
+ if (user.id === issueEntity.assignee.id) {
+ // Allowed to the issue assignee
+ return true;
+ }
+
+ const memberInProject = issueEntity.project.memberList.find(
+ (member) => member.principal.id === user.id
+ );
+ if (
+ memberInProject?.role &&
+ hasProjectPermission(
+ "bb.permission.project.admin-database",
+ memberInProject.role
+ )
+ ) {
+ // Allowed to the project owner
+ return true;
+ }
+
+ if (
+ hasWorkspacePermission("bb.permission.workspace.manage-issue", user.role)
+ ) {
+ // Allowed to DBAs and workspace owners
+ return true;
+ }
+ return false;
+ });
+
+ const rollbackEnabled = computed((): boolean => {
+ if (create.value) {
+ if (isTenantMode.value) {
+ // In tenant mode, all tasks share a common MigrationDetail
+ const issueCreate = issue.value as IssueCreate;
+ const createContext = issueCreate.createContext as MigrationContext;
+ const migrationDetail = head(createContext.detailList);
+ return migrationDetail?.rollbackEnabled ?? false;
+ }
+ // In standard mode, every task has a independent TaskCreate with its
+ // own rollbackEnabled field.
+ const taskCreate = task.value as TaskCreate;
+ return taskCreate.rollbackEnabled ?? false;
+ } else {
+ const taskEntity = task.value as Task;
+ const payload = taskEntity.payload as
+ | TaskDatabaseDataUpdatePayload
+ | undefined;
+ return payload?.rollbackEnabled ?? false;
+ }
+ });
+
+ const toggleRollback = (on: boolean) => {
+ if (create.value) {
+ if (isTenantMode.value) {
+ // In tenant mode, all tasks share a common MigrationDetail
+ const issueCreate = issue.value as IssueCreate;
+ const createContext = issueCreate.createContext as MigrationContext;
+ const migrationDetail = head(createContext.detailList);
+ if (migrationDetail) {
+ migrationDetail.rollbackEnabled = on;
+ }
+ } else {
+ // In standard mode, every task has a independent TaskCreate with its
+ // own rollbackEnabled field.
+ const taskCreate = task.value as TaskCreate;
+ taskCreate.rollbackEnabled = on;
+ }
+ } else {
+ // Once the issue has been created, we need to patch the task.
+ const taskEntity = task.value as Task;
+ patchTask(taskEntity.id, {
+ rollbackEnabled: on,
+ });
+ }
+ };
+
+ return {
+ rollbackUIType,
+ allowRollback,
+ rollbackEnabled,
+ toggleRollback,
+ };
+};
+
+const databaseOfTask = (task: Task | TaskCreate): Database => {
+ if (isTaskCreate(task)) {
+ return useDatabaseStore().getDatabaseById((task as TaskCreate).databaseId!);
+ }
+
+ return task.database!;
+};
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index a560c8798d..d4ecdbdc6d 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -298,7 +298,14 @@
"n-similar-tasks": "({count} similar tasks)",
"skip": "Skip",
"skip-modal-title": "Skip task [{name}]?",
- "task-checks": "Task checks"
+ "task-checks": "Task checks",
+ "rollback": {
+ "sql-rollback": "SQL Rollback",
+ "log": "Log",
+ "failed": "Failed",
+ "preview-rollback": "Preview rollback",
+ "logging": "Logging"
+ }
},
"banner": {
"demo-intro": "This is a demo version of Bytebase.",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 80ab12f702..a0e8270598 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -296,7 +296,13 @@
"n-similar-tasks": "({count} 个相似的任务)",
"skip": "跳过",
"skip-modal-title": "跳过任务[{name}]?",
- "task-checks": "任务检查项"
+ "task-checks": "任务检查项",
+ "rollback": {
+ "sql-rollback": "SQL 回滚",
+ "log": "记录",
+ "failed": "失败",
+ "logging": "记录中"
+ }
},
"banner": {
"demo-intro": "这是 Bytebase 的演示版本。",
diff --git a/frontend/src/types/issue.ts b/frontend/src/types/issue.ts
index 1a81e79df5..ab987b6fe5 100644
--- a/frontend/src/types/issue.ts
+++ b/frontend/src/types/issue.ts
@@ -53,6 +53,7 @@ export type MigrationDetail = {
sheetId?: SheetId;
earliestAllowedTs: number;
databaseId?: DatabaseId;
+ rollbackEnabled?: boolean;
};
export type UpdateSchemaGhostDetail = MigrationDetail & {
diff --git a/frontend/src/types/pipeline/task.ts b/frontend/src/types/pipeline/task.ts
index 089386416a..0be5323f66 100644
--- a/frontend/src/types/pipeline/task.ts
+++ b/frontend/src/types/pipeline/task.ts
@@ -118,9 +118,11 @@ export type TaskDatabaseDataUpdatePayload = {
statement: string;
sheetId: SheetId;
pushEvent?: VCSPushEvent;
- rollbackStatement: string;
- rollbackFromIssueId: IssueId;
- rollbackFromTaskId: TaskId;
+ rollbackEnabled: boolean;
+ rollbackStatement?: string;
+ rollbackError?: string;
+ rollbackFromIssueId?: IssueId;
+ rollbackFromTaskId?: TaskId;
};
export type TaskDatabaseRestorePayload = {
@@ -201,11 +203,13 @@ export type TaskCreate = {
collation?: string;
backupId?: BackupId;
earliestAllowedTs: number;
+ rollbackEnabled?: boolean;
};
export type TaskPatch = {
statement?: string;
earliestAllowedTs?: number;
+ rollbackEnabled?: boolean;
updatedTs?: number;
};
diff --git a/frontend/src/utils/task.ts b/frontend/src/utils/task.ts
index 2d64272146..8c5ada60a0 100644
--- a/frontend/src/utils/task.ts
+++ b/frontend/src/utils/task.ts
@@ -179,3 +179,12 @@ export const isTaskTriggeredByVCS = (task: Task): boolean => {
return false;
};
+
+export const isTaskEntity = (task: Task | TaskCreate): task is Task => {
+ const obj = task as any;
+ return typeof obj["id"] === "number";
+};
+
+export const isTaskCreate = (task: Task | TaskCreate): task is TaskCreate => {
+ return !isTaskEntity(task);
+};
diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts
index 81998cbb08..0dc73cafb8 100644
--- a/frontend/src/utils/util.ts
+++ b/frontend/src/utils/util.ts
@@ -189,16 +189,21 @@ export function removeElementBySelector(selector: string) {
document.body.querySelectorAll(selector).forEach((e) => e.remove());
}
+type CompareFunc = "gt" | "lt" | "eq" | "neq" | "gte" | "lte";
// semverCompare compares version string v1 is greater than v2.
// It should be used to handle the database pseudo semantic version likes "8.0.29-0ubuntu0.20.04.3".
-export function semverCompare(v1: string, v2: string) {
- const formatedV1 = semver.coerce(v1);
- const formatedV2 = semver.coerce(v2);
- if (!formatedV1 || !formatedV2) {
+export function semverCompare(
+ v1: string,
+ v2: string,
+ method: CompareFunc = "gt"
+) {
+ const formattedV1 = semver.coerce(v1);
+ const formattedV2 = semver.coerce(v2);
+ if (!formattedV1 || !formattedV2) {
return false;
}
- return semver.gt(formatedV1, formatedV2);
+ return semver[method](formattedV1, formattedV2);
}
export function clearObject(obj: any) {