Skip to content

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

chore: prior backup UI (#9877)

Danny Xuc4e38f39cf36
diff --git a/backend/api/v1/rollout_service_converter.go b/backend/api/v1/rollout_service_converter.go
index 0c61f37649..5e7b309bc3 100644
--- a/backend/api/v1/rollout_service_converter.go
+++ b/backend/api/v1/rollout_service_converter.go
@@ -127,6 +127,9 @@ func convertToPlanSpecChangeDatabaseConfig(config *storepb.PlanConfig_Spec_Chang
RollbackEnabled: c.RollbackEnabled,
RollbackDetail: convertToPlanSpecChangeDatabaseConfigRollbackDetail(c.RollbackDetail),
GhostFlags: c.GhostFlags,
+ PreUpdateBackupDetail: &v1pb.Plan_ChangeDatabaseConfig_PreUpdateBackupDetail{
+ Database: c.PreUpdateBackupDetail.GetDatabase(),
+ },
},
}
}
@@ -247,14 +250,21 @@ func convertPlanConfigCreateDatabaseConfig(c *v1pb.Plan_CreateDatabaseConfig) *s
func convertPlanSpecChangeDatabaseConfig(config *v1pb.Plan_Spec_ChangeDatabaseConfig) *storepb.PlanConfig_Spec_ChangeDatabaseConfig {
c := config.ChangeDatabaseConfig
+ var preUpdateBackupDetail *storepb.PlanConfig_ChangeDatabaseConfig_PreUpdateBackupDetail
+ if c.PreUpdateBackupDetail != nil && c.GetPreUpdateBackupDetail().GetDatabase() != "" {
+ preUpdateBackupDetail = &storepb.PlanConfig_ChangeDatabaseConfig_PreUpdateBackupDetail{
+ Database: c.GetPreUpdateBackupDetail().GetDatabase(),
+ }
+ }
return &storepb.PlanConfig_Spec_ChangeDatabaseConfig{
ChangeDatabaseConfig: &storepb.PlanConfig_ChangeDatabaseConfig{
- Target: c.Target,
- Sheet: c.Sheet,
- Type: storepb.PlanConfig_ChangeDatabaseConfig_Type(c.Type),
- SchemaVersion: c.SchemaVersion,
- RollbackEnabled: c.RollbackEnabled,
- GhostFlags: c.GhostFlags,
+ Target: c.Target,
+ Sheet: c.Sheet,
+ Type: storepb.PlanConfig_ChangeDatabaseConfig_Type(c.Type),
+ SchemaVersion: c.SchemaVersion,
+ RollbackEnabled: c.RollbackEnabled,
+ GhostFlags: c.GhostFlags,
+ PreUpdateBackupDetail: preUpdateBackupDetail,
},
}
}
diff --git a/frontend/src/components/IssueV1/components/StageSection/Actions/Actions.vue b/frontend/src/components/IssueV1/components/StageSection/Actions/Actions.vue
index d8db2bcb3e..238529f2f4 100644
--- a/frontend/src/components/IssueV1/components/StageSection/Actions/Actions.vue
+++ b/frontend/src/components/IssueV1/components/StageSection/Actions/Actions.vue
@@ -2,6 +2,8 @@
<div class="flex flex-col items-end gap-y-2">
<EarliestAllowedTime />
+ <PreBackupSection />
+
<RollbackSection />
<GhostSection />
@@ -11,5 +13,6 @@
<script setup lang="ts">
import EarliestAllowedTime from "./EarliestAllowedTime.vue";
import GhostSection from "./GhostSection";
+import PreBackupSection from "./PreBackupSection";
import RollbackSection from "./RollbackSection";
</script>
diff --git a/frontend/src/components/IssueV1/components/StageSection/Actions/PreBackupSection/PreBackupSection.vue b/frontend/src/components/IssueV1/components/StageSection/Actions/PreBackupSection/PreBackupSection.vue
new file mode 100644
index 0000000000..b337e7bd1c
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/StageSection/Actions/PreBackupSection/PreBackupSection.vue
@@ -0,0 +1,22 @@
+<template>
+ <div
+ v-if="showPreBackupSection"
+ class="flex items-center gap-x-3 min-h-[34px]"
+ >
+ <NTooltip>
+ <template #trigger>
+ <div class="textlabel flex items-center">Prior Backup</div>
+ </template>
+ </NTooltip>
+ <div class="w-[12rem] flex items-center gap-x-2">
+ <PreBackupSwitch />
+ </div>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import PreBackupSwitch from "./PreBackupSwitch.vue";
+import { usePreBackupContext } from "./common";
+
+const { showPreBackupSection } = usePreBackupContext();
+</script>
diff --git a/frontend/src/components/IssueV1/components/StageSection/Actions/PreBackupSection/PreBackupSwitch.vue b/frontend/src/components/IssueV1/components/StageSection/Actions/PreBackupSection/PreBackupSwitch.vue
new file mode 100644
index 0000000000..be85d28699
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/StageSection/Actions/PreBackupSection/PreBackupSwitch.vue
@@ -0,0 +1,43 @@
+<template>
+ <div class="flex items-center">
+ <NSwitch
+ :value="preBackupEnabled"
+ class="bb-pre-backup-switch"
+ :disabled="showPreBackupDisabled"
+ @update:value="togglePreBackup"
+ >
+ <template #checked>
+ <span style="font-size: 10px">{{ $t("common.on") }}</span>
+ </template>
+ <template #unchecked>
+ <span style="font-size: 10px">{{ $t("common.off") }}</span>
+ </template>
+ </NSwitch>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { NSwitch } from "naive-ui";
+import { usePreBackupContext } from "./common";
+
+const { preBackupEnabled, showPreBackupDisabled, togglePreBackup } =
+ usePreBackupContext();
+</script>
+
+<style>
+.bb-pre-backup-switch {
+ --n-width: max(
+ var(--n-rail-width),
+ calc(var(--n-rail-width) + var(--n-button-width) - var(--n-rail-height))
+ ) !important;
+}
+.bb-pre-backup-switch .n-switch__checked {
+ padding-right: calc(var(--n-rail-height) - var(--n-offset) + 1px) !important;
+}
+.bb-pre-backup-switch .n-switch__unchecked {
+ padding-left: calc(var(--n-rail-height) - var(--n-offset) + 1px) !important;
+}
+.bb-pre-backup-switch .n-switch__button-placeholder {
+ width: calc(1.25 * var(--n-rail-height)) !important;
+}
+</style>
diff --git a/frontend/src/components/IssueV1/components/StageSection/Actions/PreBackupSection/common.ts b/frontend/src/components/IssueV1/components/StageSection/Actions/PreBackupSection/common.ts
new file mode 100644
index 0000000000..2387b6ac1f
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/StageSection/Actions/PreBackupSection/common.ts
@@ -0,0 +1,65 @@
+import { computed } from "vue";
+import {
+ databaseForTask,
+ specForTask,
+ useIssueContext,
+} from "@/components/IssueV1/logic";
+import { useActuatorV1Store } from "@/store";
+import { Engine } from "@/types/proto/v1/common";
+import { Task_Type } from "@/types/proto/v1/rollout_service";
+import { isDev } from "@/utils";
+
+export const usePreBackupContext = () => {
+ const context = useIssueContext();
+ const { isCreating, issue, selectedTask: task } = context;
+
+ const showPreBackupSection = computed((): boolean => {
+ if (task.value.type !== Task_Type.DATABASE_DATA_UPDATE) {
+ return false;
+ }
+ const database = databaseForTask(issue.value, task.value);
+ const { engine } = database.instanceEntity;
+ if (engine !== Engine.MYSQL && engine !== Engine.TIDB) {
+ return false;
+ }
+ if (isDev()) {
+ return true;
+ }
+
+ return useActuatorV1Store().serverInfo?.preUpdateBackup || false;
+ });
+
+ const showPreBackupDisabled = computed((): boolean => {
+ return !isCreating.value;
+ });
+
+ const preBackupEnabled = computed((): boolean => {
+ const spec = specForTask(issue.value.planEntity, task.value);
+ const database =
+ spec?.changeDatabaseConfig?.preUpdateBackupDetail?.database;
+ return database !== undefined && database !== "";
+ });
+
+ const togglePreBackup = async (on: boolean) => {
+ if (isCreating.value) {
+ const spec = specForTask(issue.value.planEntity, task.value);
+ if (spec && spec.changeDatabaseConfig) {
+ const database = databaseForTask(issue.value, task.value);
+ if (on) {
+ spec.changeDatabaseConfig.preUpdateBackupDetail = {
+ database: database.instance + "/databases/todozp",
+ };
+ } else {
+ spec.changeDatabaseConfig.preUpdateBackupDetail = undefined;
+ }
+ }
+ }
+ };
+
+ return {
+ showPreBackupSection,
+ preBackupEnabled,
+ showPreBackupDisabled,
+ togglePreBackup,
+ };
+};
diff --git a/frontend/src/components/IssueV1/components/StageSection/Actions/PreBackupSection/index.ts b/frontend/src/components/IssueV1/components/StageSection/Actions/PreBackupSection/index.ts
new file mode 100644
index 0000000000..9ded4d6044
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/StageSection/Actions/PreBackupSection/index.ts
@@ -0,0 +1,3 @@
+import PreBackupSection from "./PreBackupSection.vue";
+
+export default PreBackupSection;