From d85be39b10c39d6378df0c407c2fa4c4e8ee57b5 Mon Sep 17 00:00:00 2001 From: 1ilit <1ilit@proton.me> Date: Fri, 27 Sep 2024 20:30:58 +0400 Subject: [PATCH] Import composite types in postgres --- src/utils/importSQL/postgres.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/utils/importSQL/postgres.js b/src/utils/importSQL/postgres.js index 5c77d7b..bcc766f 100644 --- a/src/utils/importSQL/postgres.js +++ b/src/utils/importSQL/postgres.js @@ -245,6 +245,33 @@ export function fromPostgres(ast, diagramDb = DB.GENERIC) { values: e.create_definitions.value.map((x) => x.value), }; enums.push(newEnum); + } else if (Array.isArray(e.create_definitions)) { + const type = { + name: e.name.name, + fields: [], + }; + e.create_definitions.forEach((d) => { + const field = {}; + if (d.resource === "column") { + field.name = d.column.column.expr.value; + + let type = d.definition.dataType; + if (!dbToTypes[diagramDb][type]) { + type = affinity[diagramDb][type]; + } + field.type = type; + } + if (d.definition["length"]) { + if (d.definition.scale) { + field.size = d.definition["length"] + "," + d.definition.scale; + } else { + field.size = d.definition["length"]; + } + } + + type.fields.push(field); + }); + types.push(type); } } } else if (e.type === "alter") {