From a358b56d7e4228af5c726f90fc392aa08a9e0620 Mon Sep 17 00:00:00 2001 From: Christofer <77406318+csc530@users.noreply.github.com> Date: Thu, 20 Mar 2025 14:39:49 -0400 Subject: [PATCH] Use custom types when importing from postgresql (#261) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 add custom enums or types when importing from postgresql no longer defaults to blob * allow for quoted enum/types to be correctly imported used prettier for formatting as per contributing.md the type/enum check is case sensitive as there is no way I found to verify if the type was declared in quotes (case-sensitive) or without (to-lowercase by postgres) --- src/utils/importSQL/postgres.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/utils/importSQL/postgres.js b/src/utils/importSQL/postgres.js index 7ac9052..4f01e6a 100644 --- a/src/utils/importSQL/postgres.js +++ b/src/utils/importSQL/postgres.js @@ -38,11 +38,19 @@ export function fromPostgres(ast, diagramDb = DB.GENERIC) { if (d.resource === "column") { field.name = d.column.column.expr.value; - let type = d.definition.dataType; - if (!dbToTypes[diagramDb][type]) { + let type = types.find((t) => + new RegExp(`^(${t.name}|"${t.name}")$`).test( + d.definition.dataType, + ), + )?.name; + type ??= enums.find((t) => + new RegExp(`^(${t.name}|"${t.name}")$`).test( + d.definition.dataType, + ), + )?.name; + if (!type && !dbToTypes[diagramDb][type]) type = affinity[diagramDb][type]; - } - field.type = type; + field.type = type || d.definition.dataType; if (d.definition.expr && d.definition.expr.type === "expr_list") { field.values = d.definition.expr.value.map((v) => v.value);