Skip to content

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

chore: add partition tables data table (#9570)

boojackdb9de2d9d112
diff --git a/frontend/src/components/ColumnDataTable/index.vue b/frontend/src/components/ColumnDataTable/index.vue
index 46a58b1e48..84a8382514 100644
--- a/frontend/src/components/ColumnDataTable/index.vue
+++ b/frontend/src/components/ColumnDataTable/index.vue
@@ -6,7 +6,6 @@
:virtual-scroll="true"
:striped="true"
:bordered="true"
- :bottom-bordered="true"
/>
</template>
diff --git a/frontend/src/components/DatabaseOverviewPanel.vue b/frontend/src/components/DatabaseOverviewPanel.vue
index 9f18aa91fa..c5937c23d3 100644
--- a/frontend/src/components/DatabaseOverviewPanel.vue
+++ b/frontend/src/components/DatabaseOverviewPanel.vue
@@ -231,7 +231,7 @@ watch(
await dbSchemaStore.getOrFetchDatabaseMetadata({
database: database,
skipCache: false,
- view: DatabaseMetadataView.DATABASE_METADATA_VIEW_BASIC,
+ view: DatabaseMetadataView.DATABASE_METADATA_VIEW_FULL,
});
if (schemaList.value.length > 0) {
const schemaInQuery = route.query.schema as string;
diff --git a/frontend/src/components/PartitionTablesDataTable.vue b/frontend/src/components/PartitionTablesDataTable.vue
new file mode 100644
index 0000000000..b8d7c78cad
--- /dev/null
+++ b/frontend/src/components/PartitionTablesDataTable.vue
@@ -0,0 +1,110 @@
+<template>
+ <NDataTable
+ v-bind="$attrs"
+ :columns="dataTableColumns"
+ :data="dataTableRows"
+ :virtual-scroll="true"
+ :striped="true"
+ :max-height="640"
+ />
+</template>
+
+<script lang="ts" setup>
+import { NDataTable } from "naive-ui";
+import { computed, h } from "vue";
+import { useI18n } from "vue-i18n";
+import TextOverflowPopover from "@/components/misc/TextOverflowPopover.vue";
+import {
+ TableMetadata,
+ TablePartitionMetadata,
+ TablePartitionMetadata_Type,
+} from "@/types/proto/v1/database_service";
+
+type PartitionTableRowData = {
+ name: string;
+ type: string;
+ expression: string;
+ children: PartitionTableRowData[];
+};
+
+const props = defineProps<{
+ table: TableMetadata;
+ search?: string;
+}>();
+
+const { t } = useI18n();
+const partitionTables = computed(() => props.table.partitions);
+
+const dataTableColumns = computed(() => {
+ const NAME_COLUMN = {
+ title: t("common.name"),
+ key: "name",
+ resizable: true,
+ width: 140,
+ ellipsis: true,
+ };
+ const TYPE_COLUMN = {
+ title: t("common.type"),
+ key: "type",
+ resizable: true,
+ width: 140,
+ ellipsis: true,
+ };
+ const EXPRESSION_COLUMN = {
+ title: "Expression",
+ key: "expression",
+ resizable: true,
+ ellipsis: true,
+ render: (row: PartitionTableRowData) => {
+ return h(TextOverflowPopover, {
+ content: row.expression,
+ placement: "bottom",
+ lineWrap: false,
+ contentClass: "line-clamp-1 flex-1",
+ maxPopoverContentLength: 1000,
+ });
+ },
+ };
+
+ return [NAME_COLUMN, TYPE_COLUMN, EXPRESSION_COLUMN].filter(
+ (column) => column
+ );
+});
+
+const dataTableRows = computed(() => {
+ const generateRows = (
+ partitionTables: TablePartitionMetadata[]
+ ): PartitionTableRowData[] => {
+ return partitionTables
+ .filter((table) =>
+ props.search
+ ? table.name.toLowerCase().includes(props.search?.toLowerCase())
+ : true
+ )
+ .map((table: TablePartitionMetadata) => {
+ return {
+ name: table.name,
+ type: stringifyPartitionTableType(table.type),
+ expression: table.expression,
+ children: generateRows(table.subpartitions),
+ };
+ });
+ };
+
+ return generateRows(partitionTables.value);
+});
+
+const stringifyPartitionTableType = (
+ type: TablePartitionMetadata_Type
+): string => {
+ if (type === TablePartitionMetadata_Type.HASH) {
+ return "HASH";
+ } else if (type === TablePartitionMetadata_Type.RANGE) {
+ return "RANGE";
+ } else if (type === TablePartitionMetadata_Type.LIST) {
+ return "LIST";
+ } else {
+ return "UNKNOWN";
+ }
+};
+</script>
diff --git a/frontend/src/components/TableDataTable.vue b/frontend/src/components/TableDataTable.vue
index 5f57573001..5533bac043 100644
--- a/frontend/src/components/TableDataTable.vue
+++ b/frontend/src/components/TableDataTable.vue
@@ -7,7 +7,6 @@
:virtual-scroll="true"
:striped="true"
:bordered="true"
- :bottom-bordered="true"
/>
<TableDetailDrawer
@@ -102,6 +101,13 @@ const hasEngineProperty = computed(() => {
return !isPostgres.value;
});
+const hasPartitionTables = computed(() => {
+ return (
+ // Only show partition tables for PostgreSQL.
+ engine.value === Engine.POSTGRES
+ );
+});
+
const columns = computed(() => {
const columns: (DataTableColumn<TableMetadata> & { hide?: boolean })[] = [
{
@@ -138,6 +144,14 @@ const columns = computed(() => {
});
},
},
+ {
+ key: "partitioned",
+ title: t("database.partitioned"),
+ hide: !hasPartitionTables.value,
+ render: (table) => {
+ return table.partitions.length > 0 ? "True" : "";
+ },
+ },
{
key: "rowCountEst",
title: t("database.row-count-est"),
diff --git a/frontend/src/components/TableDetailDrawer.vue b/frontend/src/components/TableDetailDrawer.vue
index f319d8d51b..61e119bdc6 100644
--- a/frontend/src/components/TableDetailDrawer.vue
+++ b/frontend/src/components/TableDetailDrawer.vue
@@ -163,6 +163,25 @@
</div>
</div>
+ <div v-if="shouldShowPartitionTablesDataTable" class="mt-6 px-6">
+ <div class="mb-4 w-full flex flex-row justify-between items-center">
+ <div class="text-lg leading-6 font-medium text-main">
+ {{ $t("database.partition-tables") }}
+ </div>
+ <div>
+ <SearchBox
+ :value="state.partitionTableNameSearchKeyword"
+ :placeholder="$t('common.filter-by-name')"
+ @update:value="state.partitionTableNameSearchKeyword = $event"
+ />
+ </div>
+ </div>
+ <PartitionTablesDataTable
+ :table="table"
+ :search="state.partitionTableNameSearchKeyword"
+ />
+ </div>
+
<div v-if="shouldShowColumnTable" class="mt-6 px-6">
<div class="mb-4 w-full flex flex-row justify-between items-center">
<div class="text-lg leading-6 font-medium text-main">
@@ -227,9 +246,11 @@ import {
import ColumnDataTable from "./ColumnDataTable/index.vue";
import { SQLEditorButtonV1 } from "./DatabaseDetail";
import IndexTable from "./IndexTable.vue";
+import PartitionTablesDataTable from "./PartitionTablesDataTable.vue";
interface LocalState {
columnNameSearchKeyword: string;
+ partitionTableNameSearchKeyword: string;
}
const props = defineProps<{
@@ -248,6 +269,7 @@ const dbSchemaStore = useDBSchemaV1Store();
const currentUserV1 = useCurrentUserV1();
const state = reactive<LocalState>({
columnNameSearchKeyword: "",
+ partitionTableNameSearchKeyword: "",
});
const table = ref<TableMetadata>();
@@ -277,9 +299,24 @@ const hasSchemaProperty = computed(
instanceEngine.value === Engine.POSTGRES ||
instanceEngine.value === Engine.RISINGWAVE
);
+
+const hasPartitionTables = computed(() => {
+ return (
+ // Only show partition tables for PostgreSQL.
+ database.value.instanceEntity.engine === Engine.POSTGRES &&
+ table.value &&
+ table.value.partitions.length > 0
+ );
+});
+
+const shouldShowPartitionTablesDataTable = computed(() => {
+ return hasPartitionTables.value;
+});
+
const shouldShowColumnTable = computed(() => {
return instanceEngine.value !== Engine.MONGODB;
});
+
const getTableName = (tableName: string) => {
if (hasSchemaProperty.value) {
return `"${props.schemaName}"."${tableName}"`;
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 1009952b9e..28136e0b71 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1672,7 +1672,9 @@
"classification": {
"self": "Classification"
},
- "recent": "Recent"
+ "recent": "Recent",
+ "partitioned": "Partitioned",
+ "partition-tables": "Partition tables"
},
"repository": {
"our-webhook-link": "The webhook created by Bytebase can be found at {webhookLink}.",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index e836234ec2..c98dfa8e3d 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1671,7 +1671,9 @@
"classification": {
"self": "Clasificación"
},
- "recent": "Reciente"
+ "recent": "Reciente",
+ "partitioned": "Particionado",
+ "partition-tabled": "Tabla particionada"
},
"repository": {
"branch-observe-file-change": "La rama donde Bytebase observa el cambio de archivo.",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 914babac53..e42f0c4bfc 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1667,7 +1667,9 @@
"classification": {
"self": "分类分级"
},
- "recent": "最近访问"
+ "recent": "最近访问",
+ "partitioned": "分区",
+ "partition-tabled": "分区表"
},
"repository": {
"branch-observe-file-change": "Bytebase 跟踪文件变更的分支。",
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 720fcb8d97..b95a68e703 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -1325,7 +1325,7 @@ router.beforeEach((to, from, next) => {
.getOrFetchDatabaseMetadata({
database: database.name,
skipCache: false,
- view: DatabaseMetadataView.DATABASE_METADATA_VIEW_BASIC,
+ view: DatabaseMetadataView.DATABASE_METADATA_VIEW_FULL,
})
.then(() => {
next();