From 804a2a5387704a0b586db7b9ffb5ef873bc28043 Mon Sep 17 00:00:00 2001 From: csc530 <77406318+csc530@users.noreply.github.com> Date: Fri, 11 Oct 2024 19:30:28 -0400 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20add=20custom=20enums=20or=20?= =?UTF-8?q?types=20when=20importing=20from=20postgresql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no longer defaults to blob --- src/utils/importSQL/postgres.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/importSQL/postgres.js b/src/utils/importSQL/postgres.js index 2912404c..13f5171c 100644 --- a/src/utils/importSQL/postgres.js +++ b/src/utils/importSQL/postgres.js @@ -38,11 +38,11 @@ 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) => t.name === d.definition.dataType)?.name + type ??= enums.find((t) => t.name === 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); From 965d1bb1454523a909590843cd2d96a58b3cb068 Mon Sep 17 00:00:00 2001 From: csc530 <77406318+csc530@users.noreply.github.com> Date: Sat, 12 Oct 2024 10:33:42 -0400 Subject: [PATCH 2/2] 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 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/utils/importSQL/postgres.js b/src/utils/importSQL/postgres.js index 13f5171c..93d73ba1 100644 --- a/src/utils/importSQL/postgres.js +++ b/src/utils/importSQL/postgres.js @@ -38,8 +38,16 @@ export function fromPostgres(ast, diagramDb = DB.GENERIC) { if (d.resource === "column") { field.name = d.column.column.expr.value; - let type = types.find((t) => t.name === d.definition.dataType)?.name - type ??= enums.find((t) => t.name === d.definition.dataType)?.name + 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 || d.definition.dataType;