Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: Deduplicate foreign schema nodes in Schema Visualizer (#41436)

Ivan Vasilova9cb6cde6c32
diff --git a/apps/studio/components/interfaces/Database/Schemas/Schemas.utils.ts b/apps/studio/components/interfaces/Database/Schemas/Schemas.utils.ts
index 4251a30e284..0dc70a1f953 100644
--- a/apps/studio/components/interfaces/Database/Schemas/Schemas.utils.ts
+++ b/apps/studio/components/interfaces/Database/Schemas/Schemas.utils.ts
@@ -69,22 +69,27 @@ export async function getGraphDataFromTables(
// Create additional [this->foreign] node that we can point to on the graph.
if (rel.target_table_schema !== currentSchema) {
- const data: TableNodeData = {
- id: rel.id,
- ref: ref!,
- schema: rel.target_table_schema,
- name: `${rel.target_table_schema}.${rel.target_table_name}.${rel.target_column_name}`,
- isForeign: true,
- columns: [],
+ const targetId = `${rel.target_table_schema}.${rel.target_table_name}.${rel.target_column_name}`
+
+ const targetNode = nodes.find((n) => n.id === targetId)
+ if (!targetNode) {
+ const data: TableNodeData = {
+ id: rel.id,
+ ref: ref!,
+ schema: rel.target_table_schema,
+ name: targetId,
+ isForeign: true,
+ columns: [],
+ }
+
+ nodes.push({
+ id: targetId,
+ type: 'table',
+ data: data,
+ position: { x: 0, y: 0 },
+ })
}
- nodes.push({
- data,
- id: rel.constraint_name,
- type: 'table',
- position: { x: 0, y: 0 },
- })
-
const [source, sourceHandle] = findTablesHandleIds(
tables,
rel.source_table_name,
@@ -96,8 +101,8 @@ export async function getGraphDataFromTables(
id: String(rel.id),
source,
sourceHandle,
- target: rel.constraint_name,
- targetHandle: rel.constraint_name,
+ target: targetId,
+ targetHandle: targetId,
})
}