Skip to content

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

feat: ghost table suffix (#1645)

Liu Jie9470ac1abe5
diff --git a/frontend/src/bbkit/BBTable/BBTable.vue b/frontend/src/bbkit/BBTable/BBTable.vue
index f5bcc47da0..e589b43c15 100644
--- a/frontend/src/bbkit/BBTable/BBTable.vue
+++ b/frontend/src/bbkit/BBTable/BBTable.vue
@@ -87,6 +87,7 @@
<slot name="body" :rowData="item" />
</tr></tbody
></template>
+ <slot name="footer" />
</table>
</template>
diff --git a/frontend/src/components/TableTable.vue b/frontend/src/components/TableTable.vue
index 885100456d..824f686949 100644
--- a/frontend/src/components/TableTable.vue
+++ b/frontend/src/components/TableTable.vue
@@ -1,44 +1,74 @@
<template>
<BBTable
:column-list="COLUMN_LIST"
- :data-source="tableList"
+ :data-source="mixedTableList"
:show-header="true"
:left-bordered="true"
:right-bordered="true"
:row-clickable="true"
+ :custom-footer="true"
@click-row="clickTable"
>
<template #body="{ rowData: table }">
- <BBTableCell :left-padding="4" class="w-16">
- {{ table.name }}
+ <BBTableCell :left-padding="4">
+ <div class="flex items-center space-x-2">
+ <span>{{ table.name }}</span>
+ <BBBadge
+ v-if="isGhostTable(table)"
+ text="gh-ost"
+ :can-remove="false"
+ class="text-xs"
+ />
+ </div>
</BBTableCell>
- <BBTableCell class="w-8">
+ <BBTableCell class="w-[14%]">
{{ table.engine }}
</BBTableCell>
- <BBTableCell class="w-8">
+ <BBTableCell class="w-[14%]">
{{ table.rowCount }}
</BBTableCell>
- <BBTableCell class="w-8">
+ <BBTableCell class="w-[14%]">
{{ bytesToString(table.dataSize) }}
</BBTableCell>
- <BBTableCell class="w-8">
+ <BBTableCell class="w-[14%]">
{{ bytesToString(table.indexSize) }}
</BBTableCell>
- <BBTableCell class="w-8">
+ <BBTableCell class="w-[14%]">
{{ humanizeTs(table.createdTs) }}
</BBTableCell>
</template>
+
+ <template v-if="hasReservedTables && !state.showReservedTableList" #footer>
+ <tfoot>
+ <tr>
+ <td :colspan="COLUMN_LIST.length" class="p-0">
+ <div
+ class="flex items-center justify-center cursor-pointer hover:bg-gray-200 py-2 text-gray-400 text-sm"
+ @click="state.showReservedTableList = true"
+ >
+ {{ $t("database.show-reserved-tables") }}
+ </div>
+ </td>
+ </tr>
+ </tfoot>
+ </template>
</BBTable>
</template>
<script lang="ts">
-import { defineComponent, PropType } from "vue";
+import { computed, defineComponent, PropType, reactive } from "vue";
import { BBTableColumn } from "../bbkit/types";
import { Table } from "../types";
import { bytesToString, databaseSlug } from "../utils";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
+const GHOST_LOGO = new URL("../assets/gh-ost-logo.png", import.meta.url).href;
+
+type LocalState = {
+ showReservedTableList: boolean;
+};
+
export default defineComponent({
name: "TableTable",
props: {
@@ -51,6 +81,10 @@ export default defineComponent({
const router = useRouter();
const { t } = useI18n();
+ const state = reactive<LocalState>({
+ showReservedTableList: false,
+ });
+
const COLUMN_LIST: BBTableColumn[] = [
{
title: t("common.name"),
@@ -72,6 +106,25 @@ export default defineComponent({
},
];
+ const regularTableList = computed(() =>
+ props.tableList.filter((table) => !isGhostTable(table))
+ );
+ const reservedTableList = computed(() =>
+ props.tableList.filter((table) => isGhostTable(table))
+ );
+ const hasReservedTables = computed(
+ () => reservedTableList.value.length > 0
+ );
+
+ const mixedTableList = computed(() => {
+ const tableList = [...regularTableList.value];
+ if (state.showReservedTableList) {
+ tableList.push(...reservedTableList.value);
+ }
+
+ return tableList;
+ });
+
const clickTable = (section: number, row: number, e: MouseEvent) => {
const table = props.tableList[row];
const url = `/db/${databaseSlug(table.database)}/table/${table.name}`;
@@ -83,10 +136,29 @@ export default defineComponent({
};
return {
+ GHOST_LOGO,
COLUMN_LIST,
+ state,
bytesToString,
clickTable,
+ hasReservedTables,
+ mixedTableList,
+ isGhostTable,
};
},
});
+
+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/locales/en-US.json b/frontend/src/locales/en-US.json
index 487ca8c1f2..d7de4c91d8 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -815,7 +815,8 @@
"restore-to-point-in-time": "Restore to point in time",
"no-earlier-than": "Restore point-in-time cannot be earlier than [{earliest}] (the earliest available backup).",
"no-later-than-now": "Restore point-in-time cannot be later than now."
- }
+ },
+ "show-reserved-tables": "Show bytebase reserved tables"
},
"repository": {
"branch-observe-file-change": "The branch where Bytebase observes the file change.",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index bf9d968233..ccc2d2e906 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -815,7 +815,8 @@
"restore-to-point-in-time": "恢复到指定时间点",
"no-earlier-than": "恢复的时间点不能早于 [{earliest}] (最早可用的备份)。",
"no-later-than-now": "恢复的时间点不能晚于当前时间。"
- }
+ },
+ "show-reserved-tables": "显示 bytebase 保留的表"
},
"repository": {
"branch-observe-file-change": "Bytebase 跟踪文件变更的分支。",