Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type size when exporting postgres #258

Merged
merged 7 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/data/datatypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,9 +857,8 @@ const postgresTypesBase = {
return field.default.length <= field.size;
},
hasCheck: true,
isSized: true,
isSized: false,
hasPrecision: false,
defaultSize: 65535,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how these changes would impact other database engines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't impact any other database, because each database have their own {database}TypesBase.

hasQuotes: true,
},
BYTEA: {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/exportSQL/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export function toPostgres(diagram) {
(field) =>
`${exportFieldComment(field.comment)}\t"${
field.name
}" ${field.type}${field.isArray ? " ARRAY" : ""}${field.notNull ? " NOT NULL" : ""}${field.unique ? " UNIQUE" : ""}${
}" ${field.type}${
field.size !== undefined && field.size !== "" ? "(" + field.size + ")" : ""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
field.size !== undefined && field.size !== "" ? "(" + field.size + ")" : ""
field.size ? "(" + field.size + ")" : ""

isn't this enough? or we need to test against undefined/empty for some reason?

Copy link
Contributor Author

@rudcode rudcode Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I just copy this from https://github.com/drawdb-io/drawdb/blob/main/src/utils/exportSQL/mysql.js#L12
But I think we need to test it against empty so it doesn't produce something like "VARCHAR()"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all fields have a size so yeah

}${field.isArray ? " ARRAY" : ""}${field.notNull ? " NOT NULL" : ""}${field.unique ? " UNIQUE" : ""}${
field.increment ? " GENERATED BY DEFAULT AS IDENTITY" : ""
}${
field.default.trim() !== ""
Expand Down
Loading