Skip to content

Free, simple, and intuitive online database diagram editor and SQL generator.

Import composite types in postgres

1ilitd85be39b10c3
diff --git a/src/utils/importSQL/postgres.js b/src/utils/importSQL/postgres.js
index 5c77d7b5..bcc766f2 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") {