fix(sidebar): dedupe MySQL table objects

This commit is contained in:
t8y2 2026-06-03 14:27:26 +08:00
parent 8bce370a0b
commit 381bdfdfd7
2 changed files with 32 additions and 2 deletions

View File

@ -231,13 +231,20 @@ export function mergeTableInfosIntoObjects(
if (objectType !== "TABLE" && objectType !== "VIEW") continue;
const name = normalizeDatabaseObjectName(table.name);
if (!name) continue;
const key = `${objectType}\0${(schema || "").toLowerCase()}\0${name.toLowerCase()}`;
const matchingObject = objects.find((obj) => {
const objName = normalizeDatabaseObjectName(obj.name);
if (objName.toLowerCase() !== name.toLowerCase()) return false;
return normalizeObjectType(obj.object_type) === objectType;
});
const tableSchema =
schema ?? (matchingObject?.schema ? normalizeDatabaseObjectName(matchingObject.schema) : undefined);
const key = `${objectType}\0${(tableSchema || "").toLowerCase()}\0${name.toLowerCase()}`;
if (seen.has(key)) continue;
seen.add(key);
merged.push({
name,
object_type: objectType,
schema,
schema: tableSchema,
comment: table.comment,
created_at: undefined,
updated_at: undefined,

View File

@ -193,3 +193,26 @@ test("mergeTableInfosIntoObjects restores views missing from object metadata", (
],
);
});
test("mergeTableInfosIntoObjects dedupes MySQL tables when object metadata carries database as schema", () => {
const merged = mergeTableInfosIntoObjects(
[
{
name: "orders",
object_type: "TABLE",
schema: "app",
comment: null,
created_at: null,
updated_at: null,
parent_schema: null,
parent_name: null,
},
],
[table("orders")],
);
assert.deepEqual(
merged.map((item) => ({ name: item.name, type: item.object_type, schema: item.schema })),
[{ name: "orders", type: "TABLE", schema: "app" }],
);
});