fix(dbml export): handle tables with same name under different schemas (#806)

This commit is contained in:
Guy Ben-Aharon
2025-07-29 14:59:08 +03:00
committed by GitHub
parent b30162d98b
commit e68837a34a
2 changed files with 255 additions and 4 deletions

View File

@@ -549,13 +549,18 @@ export function generateDBMLFromDiagram(diagram: Diagram): DBMLExportResult {
};
}) ?? [];
// Remove duplicate tables (keep first occurrence by table name)
const seenTableNames = new Set<string>();
// Remove duplicate tables (consider both schema and table name)
const seenTableIdentifiers = new Set<string>();
const uniqueTables = sanitizedTables.filter((table) => {
if (seenTableNames.has(table.name)) {
// Create a unique identifier combining schema and table name
const tableIdentifier = table.schema
? `${table.schema}.${table.name}`
: table.name;
if (seenTableIdentifiers.has(tableIdentifier)) {
return false; // Skip duplicate
}
seenTableNames.add(table.name);
seenTableIdentifiers.add(tableIdentifier);
return true; // Keep unique table
});