fix(xugu): place public synonyms after schemas
This commit is contained in:
1 parent
868502326c
commit
5bfb07eef0
4 files changed
+81
-12
No files matched your search
+11
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { appendTableTreeLoadMoreNode, buildGroupedObjectTreeNodes, buildSimpleObjectTreeNodes, buildTableTreeNodes, mergeTableInfosIntoObjects, mergeTableTreePageChildren, tablePartitionGroups, withoutTableTreeLoadMoreNodes } from "@/lib/table/tableTree";
|
||||
import { appendTableTreeLoadMoreNode, buildGroupedObjectTreeNodes, buildObjectGroupPlaceholderNodes, buildSimpleObjectTreeNodes, buildTableTreeNodes, mergeTableInfosIntoObjects, mergeTableTreePageChildren, tablePartitionGroups, withoutTableTreeLoadMoreNodes } from "@/lib/table/tableTree";
|
||||
import type { ObjectInfo, TableInfo, TreeNode } from "@/types/database";
|
||||
|
||||
const context = {
|
||||
@@ -117,6 +117,16 @@ describe("PostgreSQL custom type metadata", () => {
|
||||
});
|
||||
|
||||
describe("programmable database objects", () => {
|
||||
it("renders only the synonym group for the Xugu public-synonym scope", () => {
|
||||
const groups = buildObjectGroupPlaceholderNodes({
|
||||
...context,
|
||||
schema: "\u0000DBX_XUGU_PUBLIC_SYNONYMS",
|
||||
objectTypes: ["SYNONYM"],
|
||||
});
|
||||
|
||||
expect(groups).toEqual([expect.objectContaining({ type: "group-synonyms", label: "tree.synonyms" })]);
|
||||
});
|
||||
|
||||
it("coalesces Xugu package specification and body into one top-level node", () => {
|
||||
const objects: ObjectInfo[] = [
|
||||
{ name: "DBX_UI_PKG", object_type: "PACKAGE", schema: "APP", valid: true },
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isXuguPublicSynonymScope, isXuguPublicSynonymTreeNode, XUGU_PUBLIC_SYNONYM_SCOPE, xuguSchemaDisplayName } from "@/lib/sidebar/xuguPublicSynonyms";
|
||||
import { isXuguPublicSynonymScope, isXuguPublicSynonymTreeNode, sortXuguSchemaInfos, XUGU_PUBLIC_SYNONYM_SCOPE, xuguSchemaDisplayName } from "@/lib/sidebar/xuguPublicSynonyms";
|
||||
import { compareSidebarNames } from "@/lib/database/databaseTree";
|
||||
|
||||
describe("Xugu public synonym scope", () => {
|
||||
it("uses an independent protocol identity", () => {
|
||||
@@ -22,4 +23,20 @@ describe("Xugu public synonym scope", () => {
|
||||
expect(isXuguPublicSynonymTreeNode("postgres", "schema", XUGU_PUBLIC_SYNONYM_SCOPE)).toBe(false);
|
||||
expect(isXuguPublicSynonymTreeNode("xugu", "database", XUGU_PUBLIC_SYNONYM_SCOPE)).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps the public synonym scope after every real schema", () => {
|
||||
const schemas = [
|
||||
{ name: XUGU_PUBLIC_SYNONYM_SCOPE, comment: null },
|
||||
{ name: "SYSDBA", comment: null },
|
||||
{ name: "AppSchema", comment: null },
|
||||
{ name: "GUEST", comment: null },
|
||||
];
|
||||
|
||||
expect(sortXuguSchemaInfos(schemas, compareSidebarNames).map((schema) => schema.name)).toEqual(["AppSchema", "GUEST", "SYSDBA", XUGU_PUBLIC_SYNONYM_SCOPE]);
|
||||
});
|
||||
|
||||
it("does not treat the real GUEST schema as a public-synonym scope", () => {
|
||||
const schemas = [{ name: "GUEST" }, { name: XUGU_PUBLIC_SYNONYM_SCOPE }];
|
||||
expect(sortXuguSchemaInfos(schemas, compareSidebarNames).map((schema) => schema.name)).toEqual(["GUEST", XUGU_PUBLIC_SYNONYM_SCOPE]);
|
||||
});
|
||||
});
|
||||
@@ -6,6 +6,27 @@
|
||||
export const XUGU_PUBLIC_SYNONYM_SCOPE = "\u0000DBX_XUGU_PUBLIC_SYNONYMS";
|
||||
export const XUGU_PUBLIC_SYNONYM_SCOPE_LABEL = "Public synonyms";
|
||||
|
||||
/**
|
||||
* Keep the synthetic public-synonym scope visually separate from real
|
||||
* schemas. The scope is deliberately sorted after every real schema so a
|
||||
* database-global namespace cannot be mistaken for an ordinary owner/schema.
|
||||
*/
|
||||
export function sortXuguSchemaInfos<T extends { name: string }>(schemas: readonly T[], compareNames: (left: string, right: string) => number): T[] {
|
||||
const realSchemas: T[] = [];
|
||||
const publicSynonymScopes: T[] = [];
|
||||
|
||||
for (const schema of schemas) {
|
||||
if (isXuguPublicSynonymScope(schema.name)) {
|
||||
publicSynonymScopes.push(schema);
|
||||
} else {
|
||||
realSchemas.push(schema);
|
||||
}
|
||||
}
|
||||
|
||||
realSchemas.sort((left, right) => compareNames(left.name, right.name));
|
||||
return [...realSchemas, ...publicSynonymScopes];
|
||||
}
|
||||
|
||||
export function isXuguPublicSynonymScope(schema: string | null | undefined): boolean {
|
||||
return schema === XUGU_PUBLIC_SYNONYM_SCOPE;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user