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] 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;