feat(metadata): honor system schema visibility

This commit is contained in:
amwps290 authored and GitHub committed 2026-07-29 03:23:04 +08:00
1 parent a07def6042
commit 820b8cd26f
44 files changed
+422 -47

No files matched your search

@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { schemaOptionsForConnection } from "@/composables/useSchemaOptions";
import { schemaOptionsCacheKey, schemaOptionsForConnection } from "@/composables/useSchemaOptions";
describe("schemaOptionsForConnection", () => {
it("sorts schema names with numeric suffixes naturally", () => {
@@ -19,4 +19,19 @@ describe("schemaOptionsForConnection", () => {
expect(schemaOptionsForConnection(["WMWMSE10", "SYSTEM", "WMWMSE2", "WMWMSE1"], connection, "ORCL")).toEqual(["WMWMSE2", "WMWMSE10"]);
});
it.each(["opengauss", "kingbase"] as const)("includes system schemas for %s when enabled", (dbType) => {
expect(
schemaOptionsForConnection(["information_schema", "pg_catalog", "public"], {
db_type: dbType,
show_system_schemas: true,
}),
).toEqual(["information_schema", "pg_catalog", "public"]);
});
});
describe("schemaOptionsCacheKey", () => {
it("separates hidden and visible system-schema results", () => {
expect(schemaOptionsCacheKey("connection-1", "postgres", false)).not.toBe(schemaOptionsCacheKey("connection-1", "postgres", true));
});
});
@@ -10,7 +10,11 @@ export function hasSchemaOptionsCacheEntry(options: Record<string, string[]>, ke
return Object.prototype.hasOwnProperty.call(options, key);
}
export function schemaOptionsForConnection(schemaNames: string[], connection: Pick<ConnectionConfig, "db_type" | "driver_profile" | "visible_databases" | "visible_schemas"> | undefined, database = ""): string[] {
export function schemaOptionsCacheKey(connectionId: string, database: string, showSystemSchemas: boolean): string {
return `${connectionId}:${database}:${showSystemSchemas ? "show-system" : "hide-system"}`;
}
export function schemaOptionsForConnection(schemaNames: string[], connection: Pick<ConnectionConfig, "db_type" | "driver_profile" | "visible_databases" | "visible_schemas" | "show_system_schemas"> | undefined, database = ""): string[] {
// Keep numeric schema suffixes in human order (SCHEMA2 before SCHEMA10), matching the database tree.
return sortSidebarNames(filterSchemaNamesForConnection(schemaNames, connection, database));
}
@@ -22,7 +26,7 @@ export function useSchemaOptions() {
const loadingSchemaOptions = ref<Record<string, boolean>>({});
function cacheKey(connectionId: string, database: string) {
return `${connectionId}:${database}`;
return schemaOptionsCacheKey(connectionId, database, connectionStore.getConfig(connectionId)?.show_system_schemas === true);
}
function isSchemaAware(connectionId: string): boolean {