Skip to content

Commit

Permalink
Import composite types in postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilit committed Sep 27, 2024
1 parent 1721471 commit d85be39
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/utils/importSQL/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,33 @@ export function fromPostgres(ast, diagramDb = DB.GENERIC) {
values: e.create_definitions.value.map((x) => x.value),
};
enums.push(newEnum);
} else if (Array.isArray(e.create_definitions)) {
const type = {
name: e.name.name,
fields: [],
};
e.create_definitions.forEach((d) => {
const field = {};
if (d.resource === "column") {
field.name = d.column.column.expr.value;

let type = d.definition.dataType;
if (!dbToTypes[diagramDb][type]) {
type = affinity[diagramDb][type];
}
field.type = type;
}
if (d.definition["length"]) {
if (d.definition.scale) {
field.size = d.definition["length"] + "," + d.definition.scale;
} else {
field.size = d.definition["length"];
}
}

type.fields.push(field);
});
types.push(type);
}
}
} else if (e.type === "alter") {
Expand Down

0 comments on commit d85be39

Please sign in to comment.