diff --git a/apps/desktop/src/composables/useSchemaOptions.ts b/apps/desktop/src/composables/useSchemaOptions.ts index 764b849619..07cf3f6ce5 100644 --- a/apps/desktop/src/composables/useSchemaOptions.ts +++ b/apps/desktop/src/composables/useSchemaOptions.ts @@ -1,12 +1,18 @@ import { ref } from "vue"; import { useConnectionStore } from "@/stores/connectionStore"; import { isSchemaAware as isSchemaAwareType, isSingleDatabase, usesTreeSchemaMode } from "@/lib/databaseCapabilities"; +import { filterDatabaseNamesForConnection } from "@/lib/visibleDatabases"; +import type { ConnectionConfig } from "@/types/database"; import * as api from "@/lib/api"; export function hasSchemaOptionsCacheEntry(options: Record, key: string): boolean { return Object.prototype.hasOwnProperty.call(options, key); } +export function schemaOptionsForConnection(schemaNames: string[], connection: Pick | undefined): string[] { + return filterDatabaseNamesForConnection(schemaNames, connection); +} + export function useSchemaOptions() { const connectionStore = useConnectionStore(); @@ -23,7 +29,8 @@ export function useSchemaOptions() { async function loadSchemaOptions(connectionId: string, database: string) { if (!isSchemaAware(connectionId)) return; - const dbType = connectionStore.getConfig(connectionId)?.db_type; + const connection = connectionStore.getConfig(connectionId); + const dbType = connection?.db_type; if (!database && !isSingleDatabase(dbType) && !usesTreeSchemaMode(dbType)) return; const key = cacheKey(connectionId, database); if (hasSchemaOptionsCacheEntry(schemaOptions.value, key)) return; @@ -32,7 +39,7 @@ export function useSchemaOptions() { loadingSchemaOptions.value[key] = true; try { await connectionStore.ensureConnected(connectionId); - schemaOptions.value[key] = await api.listSchemas(connectionId, database); + schemaOptions.value[key] = schemaOptionsForConnection(await api.listSchemas(connectionId, database), connection); } catch (e) { schemaOptions.value[key] = []; throw e; diff --git a/packages/app-tests/schemaOptions.test.ts b/packages/app-tests/schemaOptions.test.ts new file mode 100644 index 0000000000..eee8443823 --- /dev/null +++ b/packages/app-tests/schemaOptions.test.ts @@ -0,0 +1,23 @@ +import assert from "node:assert/strict"; +import { test } from "vitest"; +import { schemaOptionsForConnection } from "../../apps/desktop/src/composables/useSchemaOptions.ts"; + +test("schema options respect Oracle visible database filters", () => { + assert.deepEqual( + schemaOptionsForConnection(["CAM", "00010", "00012", "SYS"], { + db_type: "oracle", + visible_databases: ["CAM", "00010"], + }), + ["CAM", "00010"], + ); +}); + +test("schema options keep default system-schema filtering without explicit filters", () => { + assert.deepEqual( + schemaOptionsForConnection(["CAM", "SYS", "SYSTEM"], { + db_type: "oracle", + visible_databases: undefined, + }), + ["CAM"], + ); +});