Skip to content

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

feat(sql-editor): show schema names for tables in PostgreSQL (#4316)

Liu Ji4e268140e47d
diff --git a/frontend/src/types/connectionTree.ts b/frontend/src/types/connectionTree.ts
index d0dc69296c..33ec50409e 100644
--- a/frontend/src/types/connectionTree.ts
+++ b/frontend/src/types/connectionTree.ts
@@ -27,4 +27,8 @@ export interface ConnectionAtom {
children?: ConnectionAtom[];
disabled?: boolean;
isLeaf?: boolean;
+ table?: {
+ schema: string;
+ name: string;
+ };
}
diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
index bbce5560e3..3fa702b34d 100644
--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
@@ -196,14 +196,6 @@ const setConnection = (
/* defaultTabName */ name
);
tabStore.updateCurrentTab(target);
-
- if (connectionTreeStore.selectedTableAtom) {
- const tableAtom = connectionTreeStore.selectedTableAtom;
- if (tableAtom.parentId !== target.connection.databaseId) {
- // Switching database should hide the selected table schema panel
- connectionTreeStore.selectedTableAtom = undefined;
- }
- }
};
// If selected item is instance node
@@ -256,19 +248,27 @@ const loadSubTree = async (option: TreeOption): Promise<void> => {
const item = option as any as ConnectionAtom;
if (item.type === "database") {
const database = databaseStore.getDatabaseById(item.id);
- const tableList = await dbSchemaStore.getOrFetchTableListByDatabaseId(
+ const schemaList = await dbSchemaStore.getOrFetchSchemaListByDatabaseId(
item.id as DatabaseId
);
+ item.children = schemaList.flatMap((schema) => {
+ return schema.tables.map((table) => {
+ const node = generateTableItem(
+ connectionTreeStore.mapAtom(table, "table", item.id)
+ );
+ node.table = {
+ schema: schema.name,
+ name: table.name,
+ };
+ if (schema.name) {
+ node.label = `${schema.name}.${node.label}`;
+ }
+ if (database.instance.engine === "MONGODB") {
+ node.disabled = true;
+ }
- item.children = tableList.map((table) => {
- const node = generateTableItem(
- connectionTreeStore.mapAtom(table, "table", item.id)
- );
- if (database.instance.engine === "MONGODB") {
- node.disabled = true;
- }
-
- return node;
+ return node;
+ });
});
if (item.children.length === 0) {
// No tables in the db
@@ -384,6 +384,22 @@ const scrollToConnectedNode = (
});
};
+// Hide the selected table schema panel when switching to another database
+// or instance.
+watch(
+ [
+ () => connectionTreeStore.selectedTableAtom,
+ () => tabStore.currentTab.connection.databaseId,
+ ],
+ ([tableAtom, databaseId]) => {
+ if (tableAtom) {
+ if (tableAtom.parentId !== databaseId) {
+ connectionTreeStore.selectedTableAtom = undefined;
+ }
+ }
+ }
+);
+
// Open corresponding tree node when the connection changed.
watch(
[
diff --git a/frontend/src/views/sql-editor/AsidePanel/TableSchema.vue b/frontend/src/views/sql-editor/AsidePanel/TableSchema.vue
index 303be17115..ec4c34db1e 100644
--- a/frontend/src/views/sql-editor/AsidePanel/TableSchema.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/TableSchema.vue
@@ -1,8 +1,9 @@
<template>
- <div v-if="table !== undefined" class="table-schema">
+ <div v-if="schema && table" class="table-schema">
<div class="table-schema--header">
<div class="table-schema--header-title mr-1 flex items-center">
<heroicons-outline:table class="h-4 w-4 mr-1" />
+ <span v-if="schema.name" class="font-semibold">{{ schema.name }}.</span>
<span class="font-semibold">{{ table.name }}</span>
</div>
<div
@@ -37,7 +38,7 @@
</div>
<div class="flex justify-between items-center w-full text-xs py-2">
<div class="table-schema--content-column">
- <span>Columns</span>
+ <span>{{ $t("database.columns") }}</span>
</div>
<div class="table-schema--content-column">
<span>Data Type</span>
@@ -85,14 +86,20 @@ const connectionTreeStore = useConnectionTreeStore();
const databaseStore = useDatabaseStore();
const dbSchemaStore = useDBSchemaStore();
const tableAtom = computed(() => connectionTreeStore.selectedTableAtom);
+const schema = computed(() => {
+ const atom = tableAtom.value;
+ if (isUndefined(atom)) {
+ return undefined;
+ }
+ const schemaList = dbSchemaStore.getSchemaListByDatabaseId(atom.parentId);
+ return schemaList.find((schema) => schema.name === atom.table?.schema);
+});
const table = computed(() => {
- if (isUndefined(tableAtom.value)) {
+ const atom = tableAtom.value;
+ if (isUndefined(atom)) {
return undefined;
}
- return dbSchemaStore.getTableByDatabaseIdAndTableName(
- tableAtom.value.parentId,
- tableAtom.value.label
- );
+ return schema.value?.tables.find((table) => table.name === atom.table?.name);
});
const gotoAlterSchema = () => {