Skip to content

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

feat(frontend): add a gh-ost or PITR badge on the detail page. (#2133)

Liu Ji6a0d87218be0
diff --git a/frontend/src/components/DatabaseTable.vue b/frontend/src/components/DatabaseTable.vue
index b7da6fed8a..4b7118e4a0 100644
--- a/frontend/src/components/DatabaseTable.vue
+++ b/frontend/src/components/DatabaseTable.vue
@@ -139,7 +139,7 @@
<script lang="ts" setup>
import { computed, PropType, reactive } from "vue";
import { useRouter } from "vue-router";
-import { connectionSlug, databaseSlug } from "../utils";
+import { connectionSlug, databaseSlug, isPITRDatabase } from "../utils";
import type { Database } from "../types";
import { DEFAULT_PROJECT_ID, UNKNOWN_ID } from "../types";
import { BBTableColumn } from "../bbkit/types";
@@ -405,10 +405,4 @@ const clickDatabase = (section: number, row: number, e: MouseEvent) => {
}
}
};
-
-function isPITRDatabase(db: Database): boolean {
- const { name } = db;
- // A pitr database's name is xxx_pitr_1234567890 or xxx_pitr_1234567890_del
- return !!name.match(/^(.+?)_pitr_(\d+)(_del)?$/);
-}
</script>
diff --git a/frontend/src/components/TableTable.vue b/frontend/src/components/TableTable.vue
index b975b71edc..beb85b6eee 100644
--- a/frontend/src/components/TableTable.vue
+++ b/frontend/src/components/TableTable.vue
@@ -60,7 +60,7 @@ import { computed, defineComponent, PropType, reactive } from "vue";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
import { Table } from "@/types";
-import { bytesToString, databaseSlug } from "@/utils";
+import { bytesToString, databaseSlug, isGhostTable } from "@/utils";
type LocalState = {
showReservedTableList: boolean;
@@ -143,18 +143,4 @@ export default defineComponent({
};
},
});
-
-function isGhostTable(table: Table): boolean {
- const { name } = table;
- // for future name support with timestamp, e.g. ~table_1234567890_del or _table_1234567890_del
- if (name.match(/^(_|~)(.+?)_(\d+)_(ghc|gho|del)$/)) {
- return true;
- }
- // for legacy name support without timestamp, e.g. _table_del or ~table_del
- if (name.match(/^(_|~)(.+?)_(ghc|gho|del)$/)) {
- return true;
- }
-
- return false;
-}
</script>
diff --git a/frontend/src/utils/database.ts b/frontend/src/utils/database.ts
index 68e6060c08..e9ae6b5ca3 100644
--- a/frontend/src/utils/database.ts
+++ b/frontend/src/utils/database.ts
@@ -80,3 +80,9 @@ export function allowGhostMigration(databaseList: Database[]): boolean {
);
});
}
+
+export function isPITRDatabase(db: Database): boolean {
+ const { name } = db;
+ // A pitr database's name is xxx_pitr_1234567890 or xxx_pitr_1234567890_del
+ return !!name.match(/^(.+?)_pitr_(\d+)(_del)?$/);
+}
diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts
index 4c7f5f84e7..38e6f7f63e 100644
--- a/frontend/src/utils/index.ts
+++ b/frontend/src/utils/index.ts
@@ -8,6 +8,7 @@ export * from "./pipeline";
export * from "./project";
export * from "./role";
export * from "./slug";
+export * from "./table";
export * from "./util";
export * from "./label";
export * from "./deployment";
diff --git a/frontend/src/utils/table.ts b/frontend/src/utils/table.ts
new file mode 100644
index 0000000000..34ec238afa
--- /dev/null
+++ b/frontend/src/utils/table.ts
@@ -0,0 +1,15 @@
+import { Table } from "@/types";
+
+export function isGhostTable(table: Table): boolean {
+ const { name } = table;
+ // for future name support with timestamp, e.g. ~table_1234567890_del or _table_1234567890_del
+ if (name.match(/^(_|~)(.+?)_(\d+)_(ghc|gho|del)$/)) {
+ return true;
+ }
+ // for legacy name support without timestamp, e.g. _table_del or ~table_del
+ if (name.match(/^(_|~)(.+?)_(ghc|gho|del)$/)) {
+ return true;
+ }
+
+ return false;
+}
diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vue
index ad89ddcb37..77e37391d3 100644
--- a/frontend/src/views/DatabaseDetail.vue
+++ b/frontend/src/views/DatabaseDetail.vue
@@ -11,9 +11,16 @@
<div>
<div class="flex items-center">
<h1
- class="pt-2 pb-2.5 text-xl font-bold leading-6 text-main truncate"
+ class="pt-2 pb-2.5 text-xl font-bold leading-6 text-main truncate flex items-center gap-x-3"
>
{{ database.name }}
+
+ <BBBadge
+ v-if="isPITRDatabase(database)"
+ text="PITR"
+ :can-remove="false"
+ class="text-xs"
+ />
</h1>
</div>
</div>
@@ -138,11 +145,10 @@
class="-mr-1 ml-2 h-5 w-5 text-control-light"
/>
</button>
- <BBTooltipButton
+ <button
v-if="allowEdit"
- type="normal"
- tooltip-mode="DISABLED-ONLY"
- :disabled="!allowMigrate"
+ type="button"
+ class="btn-normal"
@click="createMigration('bb.issue.database.schema.update')"
>
<span>{{ alterSchemaText }}</span>
@@ -150,16 +156,7 @@
v-if="database.project.workflowType == 'VCS'"
class="-mr-1 ml-2 h-5 w-5 text-control-light"
/>
- <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>
+ </button>
</div>
</div>
</main>
@@ -303,6 +300,7 @@ import {
connectionSlug,
hidePrefix,
allowGhostMigration,
+ isPITRDatabase,
} from "@/utils";
import {
ProjectId,
@@ -442,14 +440,6 @@ const allowEdit = computed(() => {
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;
@@ -484,6 +474,11 @@ const tryTransferProject = () => {
// 'online' -> online migration
// false -> user clicked cancel button
const isUsingGhostMigration = async (databaseList: Database[]) => {
+ if (database.value.project.tenantMode === "TENANT") {
+ // Not available for tenant mode now.
+ return "normal";
+ }
+
// check if all selected databases supports gh-ost
if (allowGhostMigration(databaseList)) {
// open the dialog to ask the user
diff --git a/frontend/src/views/TableDetail.vue b/frontend/src/views/TableDetail.vue
index 068582f24c..58a12d6e4f 100644
--- a/frontend/src/views/TableDetail.vue
+++ b/frontend/src/views/TableDetail.vue
@@ -11,9 +11,16 @@
<div>
<div class="flex items-center">
<h1
- class="pt-2 pb-2.5 text-xl font-bold leading-6 text-main truncate"
+ class="pt-2 pb-2.5 text-xl font-bold leading-6 text-main truncate flex items-center gap-x-3"
>
{{ table.name }}
+
+ <BBBadge
+ v-if="isGhostTable(table)"
+ text="gh-ost"
+ :can-remove="false"
+ class="text-xs"
+ />
</h1>
</div>
</div>
@@ -208,7 +215,12 @@ import { computed, defineComponent } from "vue";
import ColumnTable from "../components/ColumnTable.vue";
import IndexTable from "../components/IndexTable.vue";
import InstanceEngineIcon from "../components/InstanceEngineIcon.vue";
-import { bytesToString, connectionSlug, idFromSlug } from "../utils";
+import {
+ bytesToString,
+ connectionSlug,
+ idFromSlug,
+ isGhostTable,
+} from "../utils";
import { useRouter } from "vue-router";
import { useTableStore } from "@/store";
import { Table } from "@/types";
@@ -255,6 +267,7 @@ export default defineComponent({
database,
gotoSQLEditor,
bytesToString,
+ isGhostTable,
};
},
});