Skip to content

Database diagrams editor that allows you to visualize and design your DB with a single query.

fix: clone of custom types (#804)

Guy Ben-Aharonb30162d98bc6
diff --git a/src/lib/clone.ts b/src/lib/clone.ts
index 14200a67..2050764e 100644
--- a/src/lib/clone.ts
+++ b/src/lib/clone.ts
@@ -1,3 +1,4 @@
+import type { DBCustomType } from './domain';
import type { Area } from './domain/area';
import type { DBDependency } from './domain/db-dependency';
import type { DBField } from './domain/db-field';
@@ -48,6 +49,10 @@ const generateIdsMapFromDiagram = (
idsMap.set(area.id, generateId());
});
+ diagram.customTypes?.forEach((customType) => {
+ idsMap.set(customType.id, generateId());
+ });
+
return idsMap;
};
@@ -213,6 +218,22 @@ export const cloneDiagram = (
})
.filter((area): area is Area => area !== null) ?? [];
+ const customTypes: DBCustomType[] =
+ diagram.customTypes
+ ?.map((customType) => {
+ const id = getNewId(customType.id);
+ if (!id) {
+ return null;
+ }
+ return {
+ ...customType,
+ id,
+ } satisfies DBCustomType;
+ })
+ .filter(
+ (customType): customType is DBCustomType => customType !== null
+ ) ?? [];
+
return {
diagram: {
...diagram,
@@ -221,6 +242,7 @@ export const cloneDiagram = (
relationships,
tables,
areas,
+ customTypes,
createdAt: diagram.createdAt
? new Date(diagram.createdAt)
: new Date(),