Skip to content

Commit a358b56

Browse files
authored
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)
1 parent 6cae92c commit a358b56

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/utils/importSQL/postgres.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,19 @@ export function fromPostgres(ast, diagramDb = DB.GENERIC) {
3838
if (d.resource === "column") {
3939
field.name = d.column.column.expr.value;
4040

41-
let type = d.definition.dataType;
42-
if (!dbToTypes[diagramDb][type]) {
41+
let type = types.find((t) =>
42+
new RegExp(`^(${t.name}|"${t.name}")$`).test(
43+
d.definition.dataType,
44+
),
45+
)?.name;
46+
type ??= enums.find((t) =>
47+
new RegExp(`^(${t.name}|"${t.name}")$`).test(
48+
d.definition.dataType,
49+
),
50+
)?.name;
51+
if (!type && !dbToTypes[diagramDb][type])
4352
type = affinity[diagramDb][type];
44-
}
45-
field.type = type;
53+
field.type = type || d.definition.dataType;
4654

4755
if (d.definition.expr && d.definition.expr.type === "expr_list") {
4856
field.values = d.definition.expr.value.map((v) => v.value);

0 commit comments

Comments
 (0)