diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vue
index 11098030c..1533e0c20 100644
--- a/apps/desktop/src/components/sidebar/TreeItem.vue
+++ b/apps/desktop/src/components/sidebar/TreeItem.vue
@@ -3127,6 +3127,7 @@ const paddingLeft = computed(() => treeItemPaddingLeft(props.depth));
const isConnected = computed(() => props.node.type === "connection" && !!props.node.connectionId && connectionStore.connectedIds.has(props.node.connectionId));
const isConnectionReadonly = computed(() => props.node.type === "connection" && !!props.node.connectionId && (connectionStore.getConfig(props.node.connectionId)?.read_only ?? false));
const isOpenedDatabase = computed(() => isSidebarDatabaseOpened(props.node, connectionStore.isTreeNodeChildrenLoaded));
+const showsDatabaseOpenIndicator = computed(() => props.node.type === "database" && (isOpenedDatabase.value || (!!props.node.connectionId && props.node.database != null && queryStore.isDatabaseOpen(props.node.connectionId, props.node.database))));
const canCloseDatabaseConnection = computed(() => canCloseSidebarDatabaseConnection(props.node, connectionStore.isTreeNodeChildrenLoaded));
const nodeIconClass = computed(() => {
const infoClass = getIconInfo(props.node)?.colorClass;
@@ -4135,6 +4136,7 @@ function treeItemMenuItems(): ContextMenuItem[] {
+
{{ t("connection.readOnlyBadge") }}
diff --git a/apps/desktop/src/stores/__tests__/queryStore.database-open.spec.ts b/apps/desktop/src/stores/__tests__/queryStore.database-open.spec.ts
new file mode 100644
index 000000000..47b2f88c3
--- /dev/null
+++ b/apps/desktop/src/stores/__tests__/queryStore.database-open.spec.ts
@@ -0,0 +1,40 @@
+import { createPinia, setActivePinia } from "pinia";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+function installLocalStorage() {
+ const data = new Map();
+ vi.stubGlobal("localStorage", {
+ getItem: vi.fn((key: string) => data.get(key) ?? null),
+ setItem: vi.fn((key: string, value: string) => data.set(key, value)),
+ removeItem: vi.fn((key: string) => data.delete(key)),
+ });
+}
+
+describe("queryStore database open state", () => {
+ beforeEach(() => {
+ vi.resetModules();
+ vi.unstubAllGlobals();
+ installLocalStorage();
+ setActivePinia(createPinia());
+ });
+
+ it("tracks whether a connection database has open tabs", async () => {
+ const { useQueryStore } = await import("@/stores/queryStore");
+ const store = useQueryStore();
+
+ const tabId = store.createTab("pg-1", "app", "query_1");
+
+ expect(store.isDatabaseOpen("pg-1", "app")).toBe(true);
+ expect(store.isDatabaseOpen("pg-1", "analytics")).toBe(false);
+ expect(store.isDatabaseOpen("pg-2", "app")).toBe(false);
+
+ store.updateDatabase(tabId, "analytics");
+
+ expect(store.isDatabaseOpen("pg-1", "app")).toBe(false);
+ expect(store.isDatabaseOpen("pg-1", "analytics")).toBe(true);
+
+ store.closeTab(tabId);
+
+ expect(store.isDatabaseOpen("pg-1", "analytics")).toBe(false);
+ });
+});
diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.ts
index f383541d2..00e08427c 100644
--- a/apps/desktop/src/stores/queryStore.ts
+++ b/apps/desktop/src/stores/queryStore.ts
@@ -984,6 +984,10 @@ export const useQueryStore = defineStore("query", () => {
releaseTabsWhere((tab) => tab.connectionId === connectionId && tab.database === database);
}
+ function isDatabaseOpen(connectionId: string, database: string) {
+ return tabs.value.some((tab) => tab.connectionId === connectionId && tab.database === database);
+ }
+
function updateSql(id: string, sql: string) {
const tab = tabs.value.find((t) => t.id === id);
if (tab) {
@@ -2484,6 +2488,7 @@ export const useQueryStore = defineStore("query", () => {
closeDatabaseTabs,
releaseConnectionTabs,
releaseDatabaseTabs,
+ isDatabaseOpen,
updateSql,
updateEditorViewport,
updateEditorSelection,