Skip to content

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

feat(sql-editor): add a button in the left bar to sync the specific database (#11541)

Liu Ji7b7c391f9fd5
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 5b13d3dd26..3a734f7d34 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2230,7 +2230,10 @@
"view-database-detail": "View database detail",
"copy-all-column-names": "Copy all column names",
"view-schema-text": "View schema text",
- "override-current-statement": "Override current statement"
+ "override-current-statement": "Override current statement",
+ "last-synced": "Last synced: {time}",
+ "click-to-sync-now": "Click to sync now",
+ "sync-in-progress": "Sync in progress"
},
"schema-editor": {
"self": "Schema Editor",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index fb3b646de3..24aa368541 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2230,7 +2230,10 @@
"view-database-detail": "Ver detalle de la base de datos",
"copy-all-column-names": "Copiar todos los nombres de las columnas",
"view-schema-text": "Ver texto del esquema",
- "override-current-statement": "Anular la declaración actual"
+ "override-current-statement": "Anular la declaración actual",
+ "last-synced": "Última sincronización: {hora}",
+ "click-to-sync-now": "Haga clic para sincronizar ahora",
+ "sync-in-progress": "Sincronización en progreso"
},
"schema-editor": {
"self": "Editor de esquema",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index d2c27f279e..d1d845fd52 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2230,7 +2230,10 @@
"view-database-detail": "データベースの詳細を表示する",
"copy-all-column-names": "すべての列名をコピーします",
"view-schema-text": "スキーマテキストの表示",
- "override-current-statement": "現在のステートメントをオーバーライドする"
+ "override-current-statement": "現在のステートメントをオーバーライドする",
+ "last-synced": "最終同期: {time}",
+ "click-to-sync-now": "今すぐ同期するにはクリックしてください",
+ "sync-in-progress": "同期中"
},
"schema-editor": {
"self": "スキーマエディター",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index cb87a1d244..211fc55774 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -2230,7 +2230,10 @@
"view-database-detail": "Xem chi tiết cơ sở dữ liệu",
"copy-all-column-names": "Sao chép tất cả tên cột",
"view-schema-text": "Xem văn bản lược đồ",
- "override-current-statement": "Ghi đè câu lệnh hiện tại"
+ "override-current-statement": "Ghi đè câu lệnh hiện tại",
+ "last-synced": "Đồng bộ hóa lần cuối: {time}",
+ "click-to-sync-now": "Bấm để đồng bộ ngay",
+ "sync-in-progress": "Đang đồng bộ hóa"
},
"schema-editor": {
"self": "Trình chỉnh sửa lược đồ",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 868af53580..b6ade17eec 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2230,7 +2230,10 @@
"view-database-detail": "查看数据库详情",
"copy-all-column-names": "复制所有列名",
"view-schema-text": "查看文本 Schema",
- "override-current-statement": "覆盖当前语句"
+ "override-current-statement": "覆盖当前语句",
+ "last-synced": "上次同步时间:{time}",
+ "click-to-sync-now": "点击立即同步",
+ "sync-in-progress": "正在同步"
},
"schema-editor": {
"self": "Schema 编辑器",
diff --git a/frontend/src/store/modules/v1/database.ts b/frontend/src/store/modules/v1/database.ts
index 7a7ba8aa59..752954ac31 100644
--- a/frontend/src/store/modules/v1/database.ts
+++ b/frontend/src/store/modules/v1/database.ts
@@ -67,10 +67,13 @@ export const useDatabaseV1Store = defineStore("database_v1", () => {
const composedDatabaseList = await upsertDatabaseMap(databases);
return composedDatabaseList;
};
- const syncDatabase = async (database: string) => {
+ const syncDatabase = async (database: string, refresh = false) => {
await databaseServiceClient.syncDatabase({
name: database,
});
+ if (refresh) {
+ await fetchDatabaseByName(database);
+ }
};
const databaseListByUser = (user: User) => {
return databaseList.value.filter((db) => {
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
index be958bf7c0..4e4a3a7113 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue
@@ -1,11 +1,16 @@
<template>
<div class="gap-y-1 h-full flex flex-col relative">
- <div class="px-1">
- <SearchBox
- v-model:value="searchPattern"
- size="small"
- style="width: 100%; max-width: 100%"
- />
+ <div class="px-1 flex flex-row gap-1">
+ <div class="flex-1">
+ <SearchBox
+ v-model:value="searchPattern"
+ size="small"
+ style="width: 100%; max-width: 100%"
+ />
+ </div>
+ <div class="shrink-0 flex items-center">
+ <SyncSchemaButton :database="database" :metadata="metadata" />
+ </div>
</div>
<div
@@ -79,6 +84,7 @@ import { findAncestor, isDescendantOf } from "@/utils";
import { useSQLEditorContext } from "../../context";
import { provideHoverStateContext } from "./HoverPanel";
import HoverPanel from "./HoverPanel";
+import SyncSchemaButton from "./SyncSchemaButton.vue";
import { Label } from "./TreeNode";
import { selectAllFromTableOrView, useDropdown } from "./actions";
import {
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SyncSchemaButton.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SyncSchemaButton.vue
new file mode 100644
index 0000000000..7b7286a57a
--- /dev/null
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SyncSchemaButton.vue
@@ -0,0 +1,71 @@
+<template>
+ <NPopover :disabled="disabled" placement="bottom-start">
+ <template #trigger>
+ <NButton
+ size="small"
+ style="--n-padding: 0 5px"
+ :disabled="disabled || isSyncing"
+ @click="syncNow"
+ >
+ <template #icon>
+ <RefreshCcwIcon
+ class="w-4 h-4"
+ :class="[isSyncing && 'animate-[spin_2s_linear_infinite]']"
+ />
+ </template>
+ </NButton>
+ </template>
+ <template #default>
+ <div class="flex flex-col gap-1">
+ <i18n-t tag="div" keypath="sql-editor.last-synced">
+ <template #time>
+ <HumanizeDate :date="database.successfulSyncTime" />
+ </template>
+ </i18n-t>
+ <div v-if="!isSyncing">{{ $t("sql-editor.click-to-sync-now") }}</div>
+ <div v-if="isSyncing">{{ $t("sql-editor.sync-in-progress") }}</div>
+ </div>
+ </template>
+ </NPopover>
+</template>
+
+<script setup lang="ts">
+import { RefreshCcwIcon } from "lucide-vue-next";
+import { NButton, NPopover } from "naive-ui";
+import { computed, ref } from "vue";
+import HumanizeDate from "@/components/misc/HumanizeDate.vue";
+import {
+ useConnectionOfCurrentSQLEditorTab,
+ useDBSchemaV1Store,
+ useDatabaseV1Store,
+} from "@/store";
+import { UNKNOWN_ID } from "@/types";
+
+const { database } = useConnectionOfCurrentSQLEditorTab();
+
+const disabled = computed(() => {
+ return database.value.uid === String(UNKNOWN_ID);
+});
+
+const isSyncing = ref(false);
+
+const syncNow = async () => {
+ if (disabled.value) {
+ return;
+ }
+ try {
+ isSyncing.value = true;
+ await useDatabaseV1Store().syncDatabase(
+ database.value.name,
+ /* refresh */ true
+ );
+
+ await useDBSchemaV1Store().getOrFetchDatabaseMetadata({
+ database: database.value.name,
+ skipCache: true,
+ });
+ } finally {
+ isSyncing.value = false;
+ }
+};
+</script>
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/common.ts b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/common.ts
index c8ed1f8a1b..0ade28f1ec 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/common.ts
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/common.ts
@@ -230,9 +230,6 @@ export const mapTreeNodeByType = <T extends NodeType>(
isLeaf: isLeafNodeType(type),
...overrides,
};
- if (type === "column") {
- console.log(node.isLeaf);
- }
return node;
};