Use custom types when importing from postgresql (#261)

* 🐛 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)
This commit is contained in:
Christofer 2025-03-20 14:39:49 -04:00 committed by GitHub
parent 6cae92ce10
commit a358b56d7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);