Skip to content

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

feat: disable single db migration in tenant mode (#784)

Liu Ji8dbe812fe139
diff --git a/frontend/src/bbkit/BBTooltipButton.vue b/frontend/src/bbkit/BBTooltipButton.vue
new file mode 100644
index 0000000000..148885e6eb
--- /dev/null
+++ b/frontend/src/bbkit/BBTooltipButton.vue
@@ -0,0 +1,95 @@
+<template>
+ <NTooltip trigger="manual" :show="state.tooltipVisible">
+ <template #trigger>
+ <!--
+ <button disabled> will swallow all mouse related events like mouseover/mouseout...
+ so we need to handle it manually with lower level DOM pointer events
+ -->
+ <button
+ type="button"
+ v-bind="$attrs"
+ :disabled="disabled"
+ :class="[`btn-${props.type}`, $attrs.class]"
+ @click.prevent="$emit('click')"
+ @pointerenter="showTooltip"
+ @pointerleave="hideTooltip"
+ >
+ <slot name="default"></slot>
+ </button>
+ </template>
+ <slot name="tooltip"></slot>
+ </NTooltip>
+</template>
+
+<script lang="ts">
+export default {
+ name: "BBButton",
+ inheritAttrs: false,
+};
+</script>
+
+<script lang="ts" setup>
+import {
+ defineProps,
+ withDefaults,
+ defineEmits,
+ computed,
+ reactive,
+ watch,
+ useSlots,
+} from "vue";
+
+export type ButtonType =
+ | "normal"
+ | "primary"
+ | "secondary"
+ | "cancel"
+ | "danger"
+ | "success";
+
+export type TooltipMode = "ALWAYS" | "DISABLED-ONLY";
+
+const props = withDefaults(
+ defineProps<{
+ type: ButtonType;
+ disabled: boolean;
+ tooltipMode: TooltipMode;
+ }>(),
+ {
+ type: "normal",
+ disabled: false,
+ tooltipMode: "ALWAYS",
+ }
+);
+
+defineEmits<{
+ (event: "click"): void;
+}>();
+
+const slots = useSlots();
+
+const state = reactive({
+ tooltipVisible: false,
+});
+
+const tooltipEnabled = computed(() => {
+ if (props.tooltipMode === "ALWAYS") return true;
+ if (!slots.tooltip) return false;
+ return props.disabled;
+});
+
+const showTooltip = () => {
+ if (!tooltipEnabled.value) return;
+ state.tooltipVisible = true;
+};
+
+const hideTooltip = () => {
+ state.tooltipVisible = false;
+};
+
+watch(tooltipEnabled, (enable) => {
+ if (!enable) {
+ state.tooltipVisible = false;
+ }
+});
+</script>
diff --git a/frontend/src/bbkit/index.ts b/frontend/src/bbkit/index.ts
index f793b52af6..01b6dc6cac 100644
--- a/frontend/src/bbkit/index.ts
+++ b/frontend/src/bbkit/index.ts
@@ -1,6 +1,7 @@
import BBAlert from "./BBAlert.vue";
import BBAttention from "./BBAttention.vue";
import BBAvatar from "./BBAvatar.vue";
+import BBTooltipButton from "./BBTooltipButton.vue";
import BBButtonAdd from "./BBButtonAdd.vue";
import BBButtonConfirm from "./BBButtonConfirm.vue";
import BBCheckbox from "./BBCheckbox.vue";
@@ -29,6 +30,7 @@ export {
BBAlert,
BBAttention,
BBAvatar,
+ BBTooltipButton,
BBButtonAdd,
BBButtonConfirm,
BBCheckbox,
diff --git a/frontend/src/components/DatabaseMigrationHistoryPanel.vue b/frontend/src/components/DatabaseMigrationHistoryPanel.vue
index ae6b1208fb..d9fe706acd 100644
--- a/frontend/src/components/DatabaseMigrationHistoryPanel.vue
+++ b/frontend/src/components/DatabaseMigrationHistoryPanel.vue
@@ -3,16 +3,28 @@
<div
class="flex flex-row items-center text-lg leading-6 font-medium text-main space-x-2"
>
- {{ $t("migration-history.self") }}
- <button
+ <span>{{ $t("migration-history.self") }}</span>
+ <BBTooltipButton
v-if="allowEdit"
- type="button"
- class="ml-4 btn-primary"
- :disabled="state.migrationSetupStatus != 'OK'"
- @click.prevent="state.showBaselineModal = true"
+ type="primary"
+ :disabled="!allowMigrate"
+ tooltip-mode="DISABLED-ONLY"
+ @click="state.showBaselineModal = true"
>
{{ $t("migration-history.establish-baseline") }}
- </button>
+
+ <template v-if="isTenantProject" #tooltip>
+ <div class="w-52 whitespace-pre-wrap">
+ {{
+ $t("issue.not-allowed-to-single-database-in-tenant-mode", {
+ operation: $t(
+ "migration-history.establish-baseline"
+ ).toLowerCase(),
+ })
+ }}
+ </div>
+ </template>
+ </BBTooltipButton>
<div>
<BBSpin
v-if="state.loading"
@@ -58,7 +70,13 @@
</template>
<script lang="ts">
-import { computed, PropType, reactive, watchEffect } from "vue";
+import {
+ computed,
+ defineComponent,
+ PropType,
+ reactive,
+ watchEffect,
+} from "vue";
import { useStore } from "vuex";
import MigrationHistoryTable from "../components/MigrationHistoryTable.vue";
import {
@@ -78,7 +96,7 @@ interface LocalState {
loading: boolean;
}
-export default {
+export default defineComponent({
name: "DatabaseMigrationHistoryPanel",
components: { MigrationHistoryTable },
props: {
@@ -140,6 +158,20 @@ export default {
return isCurrentUserDBAOrOwner.value;
});
+ const isTenantProject = computed(() => {
+ return props.database.project.tenantMode === "TENANT";
+ });
+
+ const allowMigrate = computed(() => {
+ if (!props.allowEdit) return false;
+
+ if (state.migrationSetupStatus !== "OK") return false;
+
+ // Migrating single database in tenant mode is not allowed
+ // Since this will probably cause different migration version across a group of tenant databases
+ return !isTenantProject.value;
+ });
+
const attentionTitle = computed((): string => {
if (state.migrationSetupStatus == "NOT_EXIST") {
return (
@@ -201,11 +233,13 @@ export default {
return {
state,
allowConfigInstance,
+ isTenantProject,
+ allowMigrate,
attentionTitle,
migrationHistorySectionList,
configInstance,
doCreateBaseline,
};
},
-};
+});
</script>
diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.yml
index 5148106700..cfd73da634 100644
--- a/frontend/src/locales/en.yml
+++ b/frontend/src/locales/en.yml
@@ -399,6 +399,7 @@ issue:
assignee: Assignee
stage-select:
active: "{name} (active)"
+ not-allowed-to-single-database-in-tenant-mode: "Can't {operation} to single database in tenant mode"
alter-schema:
vcs-enabled: >-
This project has enabled VCS based version control and selecting database
diff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.yml
index cfda3b06ff..b130a12269 100644
--- a/frontend/src/locales/zh-CN.yml
+++ b/frontend/src/locales/zh-CN.yml
@@ -388,6 +388,7 @@ issue:
assignee: 审核人
stage-select:
active: "{name}(活动中)"
+ not-allowed-to-single-database-in-tenant-mode: 在多租户模式下无法对单个数据库{operation}
alter-schema:
vcs-enabled: 该项目开启了基于 VCS 的版本管理,选择下面的数据库会将您导航到相应的 Git 仓库以发起变更流程。
vcs-info: 代表项目开启了基于 VCS 的版本管理。选择该类项目下的数据库会将您导航到对应的 Git 仓库以发起变更流程。
diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vue
index 50a7e817bd..3913ccb8ad 100644
--- a/frontend/src/views/DatabaseDetail.vue
+++ b/frontend/src/views/DatabaseDetail.vue
@@ -114,30 +114,50 @@
class="-mr-1 ml-2 h-5 w-5 text-control-light"
/>
</button>
- <button
+ <BBTooltipButton
v-if="allowEdit"
- type="button"
- class="btn-normal"
- @click.prevent="changeData"
+ type="normal"
+ tooltip-mode="DISABLED-ONLY"
+ :disabled="!allowMigrate"
+ @click="changeData"
>
<span>{{ changeDataText }}</span>
<heroicons-outline:external-link
v-if="database.project.workflowType == 'VCS'"
class="-mr-1 ml-2 h-5 w-5 text-control-light"
/>
- </button>
- <button
+ <template v-if="!allowMigrate" #tooltip>
+ <div class="w-48 whitespace-pre-wrap">
+ {{
+ $t("issue.not-allowed-to-single-database-in-tenant-mode", {
+ operation: changeDataText.toLowerCase(),
+ })
+ }}
+ </div>
+ </template>
+ </BBTooltipButton>
+ <BBTooltipButton
v-if="allowEdit"
- type="button"
- class="btn-normal"
- @click.prevent="alterSchema"
+ type="normal"
+ tooltip-mode="DISABLED-ONLY"
+ :disabled="!allowMigrate"
+ @click="alterSchema"
>
<span>{{ alterSchemaText }}</span>
<heroicons-outline:external-link
v-if="database.project.workflowType == 'VCS'"
class="-mr-1 ml-2 h-5 w-5 text-control-light"
/>
- </button>
+ <template v-if="!allowMigrate" #tooltip>
+ <div class="w-48 whitespace-pre-wrap">
+ {{
+ $t("issue.not-allowed-to-single-database-in-tenant-mode", {
+ operation: alterSchemaText.toLowerCase(),
+ })
+ }}
+ </div>
+ </template>
+ </BBTooltipButton>
</div>
</div>
</main>
@@ -403,6 +423,14 @@ export default defineComponent({
return false;
});
+ const allowMigrate = computed(() => {
+ if (!allowEdit.value) return false;
+
+ // Migrating single database in tenant mode is not allowed
+ // Since this will probably cause different migration version across a group of tenant databases
+ return database.value.project.tenantMode === "DISABLED";
+ });
+
const allowEditDatabaseLabels = computed((): boolean => {
// only allowed to edit database labels when allowAdmin
return allowAdmin.value;
@@ -574,6 +602,7 @@ export default defineComponent({
allowChangeProject,
allowAdmin,
allowEdit,
+ allowMigrate,
allowEditDatabaseLabels,
tabItemList,
tryTransferProject,