feat(pg,kingbase): partition table operations and detail queries

This commit is contained in:
amwps290 authored and GitHub committed 2026-09-21 15:36:49 +08:00
1 parent 882bd130ab
commit 1000aa07b6
62 files changed
+6180 -133

No files matched your search

+69 -2
View File
@@ -45,6 +45,7 @@ import {
RefreshCw,
RefreshCcw,
TableProperties,
Network,
UserRound,
Database,
Eraser,
@@ -90,7 +91,7 @@ import TemporalCellEditor from "@/components/grid/TemporalCellEditor.vue";
import EnumCellEditor from "@/components/grid/EnumCellEditor.vue";
import DataGridReadonlyTextSelection from "@/components/grid/DataGridReadonlyTextSelection.vue";
import GridSnapshotDialog from "@/components/grid/GridSnapshotDialog.vue";
import type { QueryResult, ColumnInfo, ConstraintInfo, DatabaseType, ForeignKeyInfo, IndexInfo, TriggerInfo, TableInfoTab, QueryResultSourceColumnRef, QueryPageJumpProgress } from "@/types/database";
import type { QueryResult, ColumnInfo, ConstraintInfo, DatabaseType, ForeignKeyInfo, IndexInfo, PgTablePartitioning, TriggerInfo, TableInfoTab, QueryResultSourceColumnRef, QueryPageJumpProgress } from "@/types/database";
import { isQueryExecutionErrorResult } from "@/lib/query/queryResultError";
import { shouldNavigateFromTableInfoColumnClick } from "@/lib/table/tableInfoColumnNavigation";
import { tableInfoTabForDrawerToggle } from "@/lib/table/tableInfoTabPreference";
@@ -10438,6 +10439,16 @@ const constraintsLoaded = ref(false);
const constraintsLoading = ref(false);
const constraintsError = ref("");
const constraintsRequestGeneration = ref(0);
const partitioning = ref<PgTablePartitioning | null>(null);
const partitioningLoaded = ref(false);
const partitioningLoading = ref(false);
const partitioningError = ref("");
const partitioningRequestGeneration = ref(0);
// The Partitions tab is only offered for tables that actually are partitioned
// (a partitioned parent or a member partition). Probed lazily with the cheap
// partition-status query, not the full tree.
const isPartitionedTable = ref(false);
const partitionStatusResolved = ref(false);
// The Constraints tab hides foreign keys when a dedicated Foreign Keys tab is
// also shown (each constraint appears once; FK navigation stays in that tab).
const constraintsForTab = computed(() => constraintsForConstraintsTab(constraints.value, tableMetadataCapabilities.value.foreignKeys));
@@ -10448,6 +10459,7 @@ const activeTableInfoLoading = computed(() => {
if (activeTableInfoTab.value === "indexes") return indexesLoading.value;
if (activeTableInfoTab.value === "foreignKeys") return foreignKeysLoading.value;
if (activeTableInfoTab.value === "constraints") return constraintsLoading.value;
if (activeTableInfoTab.value === "partitions") return partitioningLoading.value;
return activeTableInfoTab.value === "triggers" && triggersLoading.value;
});
const cellDetailPanelLayout = computed(() => settingsStore.editorSettings.cellDetailPanelLayout);
@@ -10550,6 +10562,30 @@ const mongoConnectionConfig = resolvedConnectionConfig;
const canManageMongoIndexes = computed(() => resolvedDatabaseType.value === "mongodb" && !!props.connectionId && !!props.database && !!props.tableMeta?.tableName && supportsMongoIndexMutations(mongoConnectionConfig.value, props.tableMeta?.tableType));
const canShowTableIndexes = computed(() => tableMetadataCapabilities.value.indexes && (resolvedDatabaseType.value !== "mongodb" || mongoCollectionSupportsIndexes(props.tableMeta?.tableType)));
async function probeTablePartitionStatus() {
const connectionId = props.connectionId;
const database = props.database;
const schema = props.tableMeta?.schema || props.database || "";
const tableName = props.tableMeta?.tableName;
const identity = currentIndexTableIdentity.value;
if (!tableMetadataCapabilities.value.partitions || !connectionId || !database || !tableName || !identity) {
isPartitionedTable.value = false;
partitionStatusResolved.value = true;
return;
}
try {
const status = await api.getTablePartitionStatus(connectionId, database, schema, tableName);
if (identity !== currentIndexTableIdentity.value) return;
isPartitionedTable.value = status.isPartitionedParent || status.isPartition;
} catch {
// Fail closed: hide the tab rather than offering one that cannot load.
if (identity !== currentIndexTableIdentity.value) return;
isPartitionedTable.value = false;
} finally {
if (identity === currentIndexTableIdentity.value) partitionStatusResolved.value = true;
}
}
const metadataLoaders = useDataGridTableMetadataLoaders({
props,
state: {
@@ -10576,6 +10612,11 @@ const metadataLoaders = useDataGridTableMetadataLoaders({
constraintsLoaded,
constraintsLoading,
constraintsError,
partitioning,
partitioningLoaded,
partitioningLoading,
partitioningError,
partitioningRequestGeneration,
tableInfoColumnsRequestGeneration,
tableOwnerRequestGeneration,
indexesRequestGeneration,
@@ -10592,7 +10633,7 @@ const metadataLoaders = useDataGridTableMetadataLoaders({
toastMongoIndexRefreshError: (message) => toast(t("contextMenu.mongoIndexRefreshFailed", { message }), 5000),
});
const { fetchDdl, fetchTableInfoColumns, fetchTableOwner, currentIndexTableIdentity, fetchIndexes, refreshMongoIndexMetadataAfterMutation, currentForeignKeyTableIdentity, fetchForeignKeys: fetchForeignKeysMetadata, fetchTriggers, fetchConstraints } = metadataLoaders;
const { fetchDdl, fetchTableInfoColumns, fetchTableOwner, currentIndexTableIdentity, fetchIndexes, refreshMongoIndexMetadataAfterMutation, currentForeignKeyTableIdentity, fetchForeignKeys: fetchForeignKeysMetadata, fetchTriggers, fetchConstraints, fetchPartitions } = metadataLoaders;
tableMetadataLoaderFetchForeignKeys = fetchForeignKeysMetadata;
const tableInfoTabs = computed(() => {
const tabs: TableInfoTabItem[] = [];
@@ -10639,6 +10680,14 @@ const tableInfoTabs = computed(() => {
count: triggers.value.length,
});
}
if (tableMetadataCapabilities.value.partitions && isPartitionedTable.value) {
tabs.push({
id: "partitions",
label: t("structureEditor.partitions"),
icon: Network,
count: partitioning.value?.partitions.length,
});
}
return tabs;
});
const tableInfoTabListStyle = computed(() => ({
@@ -10662,6 +10711,10 @@ function toggleTableInfoDrawerPinned() {
}
async function selectTableInfoTab(tab: TableInfoTab) {
// The drawer is often opened after the table was already selected, so the
// partition status may never have been probed; do it here (once) before the
// tab list is consulted, or the Partitions tab would be missing entirely.
if (!partitionStatusResolved.value) await probeTablePartitionStatus();
const tabSupported = tableInfoTabs.value.some((item) => item.id === tab);
const nextTab = tabSupported ? tab : tableInfoTabs.value[0]?.id;
if (!nextTab) return;
@@ -10672,6 +10725,7 @@ async function selectTableInfoTab(tab: TableInfoTab) {
else if (nextTab === "foreignKeys") await fetchForeignKeys();
else if (nextTab === "constraints") await fetchConstraints();
else if (nextTab === "triggers") await fetchTriggers();
else if (nextTab === "partitions") await fetchPartitions();
}
watch(
@@ -10710,6 +10764,9 @@ async function refreshActiveTableInfo() {
} else if (activeTableInfoTab.value === "triggers") {
triggersLoaded.value = false;
await fetchTriggers();
} else if (activeTableInfoTab.value === "partitions") {
partitioningLoaded.value = false;
await fetchPartitions(true);
}
}
@@ -10742,6 +10799,13 @@ watch(
constraintsLoading.value = false;
constraintsError.value = "";
constraintsRequestGeneration.value += 1;
partitioning.value = null;
partitioningLoaded.value = false;
partitioningLoading.value = false;
partitioningError.value = "";
partitioningRequestGeneration.value += 1;
isPartitionedTable.value = false;
partitionStatusResolved.value = false;
// 表身份变更后,主动触发索引加载,确保索引指示器在切换表后立即可见
if (showIndexIndicatorsInHeader.value && canShowTableIndexes.value && currentIndexTableIdentity.value) {
void fetchIndexes();
@@ -13475,6 +13539,9 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val
:constraints="filteredConstraints"
:constraints-loading="constraintsLoading"
:constraints-error="constraintsError"
:partitioning="partitioning"
:partitions-loading="partitioningLoading"
:partitions-error="partitioningError"
:is-protected-mongo-index="isProtectedMongoIndex"
:format-column-type="gaussdbMColumnType"
@table-info-column-click="onTableInfoColumnClick"
@@ -2,8 +2,9 @@
import { KeyRound, Loader2, Trash2 } from "@lucide/vue";
import { useI18n } from "vue-i18n";
import { Button } from "@/components/ui/button";
import TablePartitionsPanel from "@/components/structure/TablePartitionsPanel.vue";
import { tableColumnDefaultDisplayValue } from "@/lib/table/tableColumnDefaultPresentation";
import type { ColumnInfo, ConstraintInfo, ForeignKeyInfo, IndexInfo, TableInfoTab, TriggerInfo } from "@/types/database";
import type { ColumnInfo, ConstraintInfo, ForeignKeyInfo, IndexInfo, PgTablePartitioning, TableInfoTab, TriggerInfo } from "@/types/database";
interface DataGridTableInfoPanelsProps {
activeTab: TableInfoTab;
@@ -23,6 +24,9 @@ interface DataGridTableInfoPanelsProps {
constraints: ConstraintInfo[];
constraintsLoading: boolean;
constraintsError: string;
partitioning: PgTablePartitioning | null;
partitionsLoading: boolean;
partitionsError: string;
isProtectedMongoIndex: (index: IndexInfo) => boolean;
formatColumnType: (dataType: string) => string;
}
@@ -214,6 +218,8 @@ const { t } = useI18n();
</div>
</div>
</div>
<TablePartitionsPanel v-else-if="props.activeTab === 'partitions'" :partitioning="props.partitioning" :loading="props.partitionsLoading" :error="props.partitionsError" :search-query="props.searchQuery" />
</template>
<style scoped>