Skip to content

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

feat(frontend): add feature gate to pitr (#1666)

Liu Ji4276f7702436
diff --git a/frontend/src/bbkit/BBModalStack.vue b/frontend/src/bbkit/BBModalStack.vue
index 2eb2631d61..280682a9d6 100644
--- a/frontend/src/bbkit/BBModalStack.vue
+++ b/frontend/src/bbkit/BBModalStack.vue
@@ -41,8 +41,9 @@ export function useModalStack() {
const active = computed(() => index.value === stack.value.length - 1);
onUnmounted(() => {
- if (index.value >= 0) {
- stack.value.splice(index.value, 1);
+ const index = stack.value.indexOf(id);
+ if (index >= 0) {
+ stack.value.splice(index, 1);
}
});
diff --git a/frontend/src/components/DatabaseDetail/PITRRestoreButton.vue b/frontend/src/components/DatabaseDetail/PITRRestoreButton.vue
index a9495f06f4..2c95deab1c 100644
--- a/frontend/src/components/DatabaseDetail/PITRRestoreButton.vue
+++ b/frontend/src/components/DatabaseDetail/PITRRestoreButton.vue
@@ -6,7 +6,13 @@
:disabled="!allowAdmin || !pitrAvailable.result"
@click="openDialog"
>
- {{ $t("database.pitr.restore-to-point-in-time") }}
+ <div class="flex items-center space-x-2">
+ <span>{{ $t("database.pitr.restore-to-point-in-time") }}</span>
+ <FeatureBadge
+ feature="bb.feature.disaster-recovery-pitr"
+ class="text-accent"
+ />
+ </div>
<template v-if="allowAdmin && !pitrAvailable.result" #tooltip>
{{ pitrAvailable.message }}
</template>
@@ -85,6 +91,12 @@
</div>
</div>
</BBModal>
+
+ <FeatureModal
+ v-if="state.showFeatureModal"
+ feature="bb.feature.disaster-recovery-pitr"
+ @cancel="state.showFeatureModal = false"
+ />
</template>
<script lang="ts" setup>
@@ -96,11 +108,13 @@ import { useI18n } from "vue-i18n";
import { Database } from "@/types";
import { usePITRLogic } from "@/plugins";
import { issueSlug } from "@/utils";
+import { featureToRef } from "@/store";
interface LocalState {
showDatabasePITRModal: boolean;
pitrTimestampMS: number;
loading: boolean;
+ showFeatureModal: boolean;
}
const props = defineProps({
@@ -121,8 +135,11 @@ const state = reactive<LocalState>({
showDatabasePITRModal: false,
pitrTimestampMS: Date.now(),
loading: false,
+ showFeatureModal: false,
});
+const hasPITRFeature = featureToRef("bb.feature.disaster-recovery-pitr");
+
const timezone = computed(() => "UTC" + dayjs().format("ZZ"));
const { pitrAvailable, doneBackupList, createPITRIssue } = usePITRLogic(
@@ -168,6 +185,11 @@ const openDialog = () => {
};
const onConfirm = async () => {
+ if (!hasPITRFeature.value) {
+ state.showFeatureModal = true;
+ return;
+ }
+
state.loading = true;
try {
diff --git a/frontend/src/components/FeatureBadge.vue b/frontend/src/components/FeatureBadge.vue
index 46e7535df4..45e3fca944 100644
--- a/frontend/src/components/FeatureBadge.vue
+++ b/frontend/src/components/FeatureBadge.vue
@@ -1,5 +1,10 @@
<template>
- <router-link v-if="!hasFeature" to="/setting/subscription" exact-active-class>
+ <router-link
+ v-if="!hasFeature"
+ to="/setting/subscription"
+ exact-active-class
+ @click.prevent="noop"
+ >
<heroicons-solid:sparkles class="w-5 h-5" />
</router-link>
</template>
@@ -21,6 +26,9 @@ export default defineComponent({
return {
hasFeature,
+ noop: () => {
+ // do nothing
+ },
};
},
});
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 96b6aaeb80..2ccbfdd436 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1312,6 +1312,10 @@
"bb-feature-online-migration": {
"title": "Online migration",
"desc": "Based on gh-ost. For large tables, it can reduce the table lock duration from hours to seconds."
+ },
+ "bb-feature-disaster-recovery-pitr": {
+ "title": "Point-in-Time-Recovery (PITR)",
+ "desc": "Restore the database state to a point in time."
}
},
"feature-sections": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 7151ee7590..08884ef4ee 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1312,6 +1312,10 @@
"bb-feature-online-migration": {
"title": "在线变更",
"desc": "基于 gh-ost。对于大表,可以把锁表的时间从小时级降低到秒级。"
+ },
+ "bb-feature-disaster-recovery-pitr": {
+ "title": "恢复到指定时间点 (PITR)",
+ "desc": "将数据库的状态恢复到一个时间点。"
}
},
"feature-sections": {
diff --git a/frontend/src/types/plan.ts b/frontend/src/types/plan.ts
index 1f8a93ed86..cdddac739a 100644
--- a/frontend/src/types/plan.ts
+++ b/frontend/src/types/plan.ts
@@ -1,5 +1,7 @@
// Check api/plan.go to understand what each feature means.
export type FeatureType =
+ // Database management
+ | "bb.feature.disaster-recovery-pitr"
// Change Workflow
| "bb.feature.schema-review-policy"
| "bb.feature.schema-drift"
@@ -46,6 +48,8 @@ export interface Plan {
// TODO: fetch the matrix from the backend instead of duplicating it here or use a JSON/YAML file
// so that it can be shared between frontend/backend.
export const FEATURE_MATRIX: Map<FeatureType, boolean[]> = new Map([
+ // Database management
+ ["bb.feature.disaster-recovery-pitr", [false, true, true]],
// Change Workflow
["bb.feature.schema-review-policy", [false, true, true]],
["bb.feature.schema-drift", [false, true, true]],