modified: backend/src/controllers/schemaController.ts

modified:   frontend/src/pages/DatabaseSchema.tsx
This commit is contained in:
2026-01-28 00:04:01 +03:00
parent 4fb92470ce
commit c5b4799dcb
2 changed files with 112 additions and 71 deletions

View File

@@ -36,7 +36,7 @@ function TableNode({ data }: { data: TableInfo & Record<string, unknown> }) {
</div>
{/* Columns */}
<div className="divide-y divide-gray-100 max-h-64 overflow-y-auto">
<div className="divide-y divide-gray-100">
{data.columns.map((col) => (
<div
key={col.name}
@@ -78,11 +78,10 @@ const nodeTypes = {
// Calculate node height based on columns count
function getNodeHeight(table: TableInfo): number {
const headerHeight = 44;
const columnHeight = 28;
const columnHeight = 26;
const fkBarHeight = table.foreign_keys.length > 0 ? 28 : 0;
const maxVisibleColumns = 10;
const visibleColumns = Math.min(table.columns.length, maxVisibleColumns);
return headerHeight + (visibleColumns * columnHeight) + fkBarHeight + 8;
// No max limit - show all columns
return headerHeight + (table.columns.length * columnHeight) + fkBarHeight + 8;
}
function getLayoutedElements(schema: SchemaData): { nodes: Node[]; edges: Edge[] } {
@@ -139,11 +138,24 @@ function getLayoutedElements(schema: SchemaData): { nodes: Node[]; edges: Edge[]
// Create edges
const edges: Edge[] = [];
let totalFks = 0;
let matchedFks = 0;
schema.tables.forEach((table) => {
const sourceId = `${table.schema}.${table.name}`;
table.foreign_keys.forEach((fk) => {
const targetTable = schema.tables.find(t => t.name === fk.references_table);
totalFks++;
// Try to find target table - check both same schema and other schemas
let targetTable = schema.tables.find(t =>
t.name === fk.references_table && t.schema === table.schema
);
// If not found in same schema, try any schema
if (!targetTable) {
targetTable = schema.tables.find(t => t.name === fk.references_table);
}
if (targetTable) {
matchedFks++;
const targetId = `${targetTable.schema}.${targetTable.name}`;
edges.push({
id: `${fk.constraint_name}`,
@@ -161,10 +173,14 @@ function getLayoutedElements(schema: SchemaData): { nodes: Node[]; edges: Edge[]
labelBgStyle: { fill: 'white', fillOpacity: 0.9 },
labelBgPadding: [4, 2] as [number, number],
});
} else {
console.warn(`[Schema] FK not matched: ${sourceId}.${fk.column} -> ${fk.references_table}.${fk.references_column}`);
}
});
});
console.log(`[Schema] Created ${edges.length} edges from ${matchedFks}/${totalFks} FKs`);
return { nodes, edges };
}