mirror of
https://github.com/drawdb-io/drawdb.git
synced 2025-05-24 02:09:17 +00:00
Fix syntax errors in types for pg export (#368)
* Fix syntax errors in types for pg export * Fix syntax errors in types for generic pg export
This commit is contained in:
parent
3e7d1ac6f6
commit
eb48fa1d35
@ -220,9 +220,11 @@ export function jsonToPostgreSQL(obj) {
|
||||
} else {
|
||||
return `CREATE TYPE ${type.name} AS (\n${type.fields
|
||||
.map((f) => `\t${f.name} ${getTypeString(f, obj.database, "postgres")}`)
|
||||
.join(
|
||||
"\n",
|
||||
)}\n);\n${type.comment != "" ? `\nCOMMENT ON TYPE ${type.name} IS '${type.comment}';\n` : ""}`;
|
||||
.join(",\n")}\n);\n${
|
||||
type.comment && type.comment.trim() != ""
|
||||
? `\nCOMMENT ON TYPE ${type.name} IS '${type.comment}';\n`
|
||||
: ""
|
||||
}`;
|
||||
}
|
||||
})}\n${obj.tables
|
||||
.map(
|
||||
|
@ -13,17 +13,17 @@ export function toPostgres(diagram) {
|
||||
const typeStatements = diagram.types
|
||||
.map(
|
||||
(type) =>
|
||||
`\nCREATE TYPE ${type.name} AS (\n${type.fields
|
||||
`CREATE TYPE ${type.name} AS (\n${type.fields
|
||||
.map((f) => `\t${f.name} ${f.type}`)
|
||||
.join("\n")}\n);\n\n${
|
||||
type.comment.trim() !== ""
|
||||
.join(",\n")}\n);\n\n${
|
||||
type.comment && type.comment.trim() !== ""
|
||||
? `\nCOMMENT ON TYPE "${type.name}" IS '${type.comment}';\n\n`
|
||||
: ""
|
||||
}`,
|
||||
)
|
||||
.join("\n");
|
||||
|
||||
return `${enumStatements}${typeStatements}${diagram.tables
|
||||
return `${enumStatements}${enumStatements.trim() !== "" ? `\n${typeStatements}` : typeStatements}${diagram.tables
|
||||
.map(
|
||||
(table) =>
|
||||
`CREATE TABLE "${table.name}" (\n${table.fields
|
||||
@ -32,7 +32,9 @@ export function toPostgres(diagram) {
|
||||
`${exportFieldComment(field.comment)}\t"${
|
||||
field.name
|
||||
}" ${field.type}${
|
||||
field.size !== undefined && field.size !== "" ? "(" + field.size + ")" : ""
|
||||
field.size !== undefined && field.size !== ""
|
||||
? "(" + field.size + ")"
|
||||
: ""
|
||||
}${field.isArray ? " ARRAY" : ""}${field.notNull ? " NOT NULL" : ""}${field.unique ? " UNIQUE" : ""}${
|
||||
field.increment ? " GENERATED BY DEFAULT AS IDENTITY" : ""
|
||||
}${
|
||||
@ -53,7 +55,7 @@ export function toPostgres(diagram) {
|
||||
.map((f) => `"${f.name}"`)
|
||||
.join(", ")})`
|
||||
: ""
|
||||
}\n);\n${
|
||||
}\n);${
|
||||
table.comment.trim() !== ""
|
||||
? `\nCOMMENT ON TABLE "${table.name}" IS '${table.comment}';\n`
|
||||
: ""
|
||||
@ -74,10 +76,10 @@ export function toPostgres(diagram) {
|
||||
)
|
||||
.join("\n")}\n`,
|
||||
)
|
||||
.join("\n")}\n${diagram.references
|
||||
.join("\n")}${diagram.references
|
||||
.map(
|
||||
(r) =>
|
||||
`ALTER TABLE "${diagram.tables[r.startTableId].name}"\nADD FOREIGN KEY("${
|
||||
`\nALTER TABLE "${diagram.tables[r.startTableId].name}"\nADD FOREIGN KEY("${
|
||||
diagram.tables[r.startTableId].fields[r.startFieldId].name
|
||||
}") REFERENCES "${diagram.tables[r.endTableId].name}"("${
|
||||
diagram.tables[r.endTableId].fields[r.endFieldId].name
|
||||
|
Loading…
Reference in New Issue
Block a user