fix(kingbase): list schema triggers with parent tables

Closes #6707
This commit is contained in:
t8y2 committed 2026-08-19 11:24:56 +00:00
1 parent e61bd75c72
commit 4c38b389ce
9 files changed
+345 -30

No files matched your search

@@ -62,6 +62,12 @@ describe("databaseObjectCapabilities", () => {
}
});
it("exposes schema triggers for Kingbase without widening Vastbase", () => {
expect(sidebarObjectKindsForDatabase("kingbase")).toContain("TRIGGER");
expect(databaseObjectCapabilities("kingbase").sourceReadable).toContain("TRIGGER");
expect(sidebarObjectKindsForDatabase("vastbase")).not.toContain("TRIGGER");
});
it("only Xugu TYPE nodes can open object source", () => {
expect(supportsTypeObjectSource("xugu")).toBe(true);
for (const dbType of ["postgres", "opengauss", "gaussdb", "kingbase", "vastbase", undefined] as const) {
+22
View File
@@ -248,6 +248,28 @@ describe("programmable database objects", () => {
]);
});
it("keeps table-scoped Kingbase triggers distinct and source-addressable", () => {
const objects: ObjectInfo[] = [
{ name: "audit_before", object_type: "TRIGGER", schema: "public", parent_schema: "public", parent_name: "items" },
{ name: "audit_before", object_type: "TRIGGER", schema: "public", parent_schema: "public", parent_name: "orders" },
];
const simple = buildSimpleObjectTreeNodes({ ...context, schema: "public", objects, databaseType: "kingbase" });
expect(simple.map((node) => ({ label: node.label, tableName: node.tableName }))).toEqual([
{ label: "audit_before (items)", tableName: "items" },
{ label: "audit_before (orders)", tableName: "orders" },
]);
expect(new Set(simple.map((node) => node.id)).size).toBe(2);
const grouped = buildGroupedObjectTreeNodes({ ...context, schema: "public", objects, databaseType: "kingbase" });
const triggers = grouped.find((node) => node.type === "group-triggers")?.children ?? [];
expect(triggers.map((node) => ({ label: node.label, objectName: node.objectName, tableName: node.tableName }))).toEqual([
{ label: "audit_before (items)", objectName: "audit_before", tableName: "items" },
{ label: "audit_before (orders)", objectName: "audit_before", tableName: "orders" },
]);
expect(new Set(triggers.map((node) => node.id)).size).toBe(2);
});
it("groups Xugu private synonyms as source objects", () => {
const objects: ObjectInfo[] = [{ name: "SYN_SHOP_USERS", object_type: "SYNONYM", schema: "SYSDBA", valid: true }];
@@ -24,10 +24,11 @@ const POSTGRES_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VI
const POSTGRES_NO_TYPE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION", "SEQUENCE"];
// Kingbase and Vastbase agents support the same user-defined type listing via
// their own metadata query, but do not expose sequences. Kept separate from
// POSTGRES_OBJECTS and POSTGRES_LIKE_OBJECTS so unverified PG-like databases
// (highgo/uxdb/redshift) never advertise TYPE.
const KINGBASE_VASTBASE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION", "TYPE"];
// their own metadata query, but do not expose sequences. Kingbase additionally
// has a verified schema-trigger path; keep Vastbase separate until its Agent
// exposes the same parent-table-aware metadata contract.
const KINGBASE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION", "TRIGGER", "TYPE"];
const VASTBASE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION", "TYPE"];
const POSTGRES_LIKE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION"];
const ORACLE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION", "SYNONYM", "PACKAGE", "PACKAGE_BODY"];
@@ -43,10 +44,10 @@ const DATABASE_TYPE_OBJECTS = new Map<DatabaseType, SidebarObjectKind[]>([
["kwdb", POSTGRES_NO_TYPE_OBJECTS],
["opengauss", POSTGRES_OBJECTS],
// postgres like
["kingbase", KINGBASE_VASTBASE_OBJECTS],
["kingbase", KINGBASE_OBJECTS],
["highgo", POSTGRES_LIKE_OBJECTS],
["uxdb", POSTGRES_LIKE_OBJECTS],
["vastbase", KINGBASE_VASTBASE_OBJECTS],
["vastbase", VASTBASE_OBJECTS],
["redshift", POSTGRES_LIKE_OBJECTS],
// oracle
["oracle", ORACLE_OBJECTS],
+17 -6
View File
@@ -636,7 +636,9 @@ export function buildSimpleObjectTreeNodes({ nodeId, connectionId, database, sch
const childSchema = obj.schema ? normalizeDatabaseObjectName(obj.schema) : schema;
const signature = obj.signature?.trim() || "";
const dedupeKey = exactObjectIdentityKey(objectType, childSchema, name, signature);
const triggerParentName = objectType === "TRIGGER" && obj.parent_name ? normalizeDatabaseObjectName(obj.parent_name) : undefined;
const triggerParentSchema = objectType === "TRIGGER" && obj.parent_schema ? normalizeDatabaseObjectName(obj.parent_schema) : undefined;
const dedupeKey = `${exactObjectIdentityKey(objectType, childSchema, name, signature)}\0${triggerParentName || ""}`;
if (seen.has(dedupeKey)) continue;
seen.add(dedupeKey);
@@ -657,8 +659,8 @@ export function buildSimpleObjectTreeNodes({ nodeId, connectionId, database, sch
} else {
const simpleNodeType = simpleObjectNodeType(objectType);
objectNodes.push({
id: objectType === "VIEW" || objectType === "MATERIALIZED_VIEW" ? entry.node.id : `${nodeId}:${childSchema ? `${childSchema}:` : ""}${name}:${signature}:${objectType}`,
label: signature && (objectType === "FUNCTION" || objectType === "PROCEDURE") ? `${name}(${signature})` : name,
id: objectType === "VIEW" || objectType === "MATERIALIZED_VIEW" ? entry.node.id : `${nodeId}:${childSchema ? `${childSchema}:` : ""}${name}:${signature}:${triggerParentName || ""}:${objectType}`,
label: signature && (objectType === "FUNCTION" || objectType === "PROCEDURE") ? `${name}(${signature})` : triggerParentName ? `${name} (${triggerParentName})` : name,
type: simpleNodeType,
objectName: name,
signature: signature || undefined,
@@ -673,6 +675,9 @@ export function buildSimpleObjectTreeNodes({ nodeId, connectionId, database, sch
connectionId,
database,
schema: childSchema,
parentSchema: triggerParentSchema,
parentName: triggerParentName,
tableName: triggerParentName,
isExpanded: false,
children: undefined,
});
@@ -826,7 +831,8 @@ export function buildGroupedObjectTreeNodes({ nodeId, connectionId, database, sc
const t = normalizeObjectType(obj.object_type);
const objectSchema = obj.schema ? normalizeDatabaseObjectName(obj.schema) : schema || "";
const signature = (obj.signature ?? "").trim();
const key = exactObjectIdentityKey(t, objectSchema, name, signature);
const triggerParentName = t === "TRIGGER" && obj.parent_name ? normalizeDatabaseObjectName(obj.parent_name) : "";
const key = `${exactObjectIdentityKey(t, objectSchema, name, signature)}\0${triggerParentName}`;
if (seen.has(key)) continue;
seen.add(key);
const arr = buckets.get(t) ?? [];
@@ -856,9 +862,11 @@ export function buildGroupedObjectTreeNodes({ nodeId, connectionId, database, sc
const objectTypeSuffix = objectType === "PACKAGE" || objectType === "PACKAGE_BODY" || objectType === "TYPE" || objectType === "TYPE_BODY" ? `:${objectType}` : "";
const signature = obj.signature?.trim() || "";
const signatureIdPart = signature && (objectType === "FUNCTION" || objectType === "PROCEDURE") ? `:${signature}` : "";
const triggerParentName = objectType === "TRIGGER" && obj.parent_name ? normalizeDatabaseObjectName(obj.parent_name) : undefined;
const triggerParentSchema = objectType === "TRIGGER" && obj.parent_schema ? normalizeDatabaseObjectName(obj.parent_schema) : undefined;
return {
id: `${nodeId}:${def.key}:${childSchema ? `${childSchema}:` : ""}${obj.name}${signatureIdPart}${objectTypeSuffix}`,
label: signature && (objectType === "FUNCTION" || objectType === "PROCEDURE") ? `${obj.name}(${signature})` : obj.name,
id: `${nodeId}:${def.key}:${childSchema ? `${childSchema}:` : ""}${obj.name}${signatureIdPart}${triggerParentName ? `:${triggerParentName}` : ""}${objectTypeSuffix}`,
label: signature && (objectType === "FUNCTION" || objectType === "PROCEDURE") ? `${obj.name}(${signature})` : triggerParentName ? `${obj.name} (${triggerParentName})` : obj.name,
type: childType,
objectName: obj.name,
signature: signature || undefined,
@@ -873,6 +881,9 @@ export function buildGroupedObjectTreeNodes({ nodeId, connectionId, database, sc
connectionId,
database,
schema: childSchema,
parentSchema: triggerParentSchema,
parentName: triggerParentName,
tableName: triggerParentName,
isExpanded: false,
children: undefined,
};