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 {
|
} else {
|
||||||
return `CREATE TYPE ${type.name} AS (\n${type.fields
|
return `CREATE TYPE ${type.name} AS (\n${type.fields
|
||||||
.map((f) => `\t${f.name} ${getTypeString(f, obj.database, "postgres")}`)
|
.map((f) => `\t${f.name} ${getTypeString(f, obj.database, "postgres")}`)
|
||||||
.join(
|
.join(",\n")}\n);\n${
|
||||||
"\n",
|
type.comment && type.comment.trim() != ""
|
||||||
)}\n);\n${type.comment != "" ? `\nCOMMENT ON TYPE ${type.name} IS '${type.comment}';\n` : ""}`;
|
? `\nCOMMENT ON TYPE ${type.name} IS '${type.comment}';\n`
|
||||||
|
: ""
|
||||||
|
}`;
|
||||||
}
|
}
|
||||||
})}\n${obj.tables
|
})}\n${obj.tables
|
||||||
.map(
|
.map(
|
||||||
|
@ -13,17 +13,17 @@ export function toPostgres(diagram) {
|
|||||||
const typeStatements = diagram.types
|
const typeStatements = diagram.types
|
||||||
.map(
|
.map(
|
||||||
(type) =>
|
(type) =>
|
||||||
`\nCREATE TYPE ${type.name} AS (\n${type.fields
|
`CREATE TYPE ${type.name} AS (\n${type.fields
|
||||||
.map((f) => `\t${f.name} ${f.type}`)
|
.map((f) => `\t${f.name} ${f.type}`)
|
||||||
.join("\n")}\n);\n\n${
|
.join(",\n")}\n);\n\n${
|
||||||
type.comment.trim() !== ""
|
type.comment && type.comment.trim() !== ""
|
||||||
? `\nCOMMENT ON TYPE "${type.name}" IS '${type.comment}';\n\n`
|
? `\nCOMMENT ON TYPE "${type.name}" IS '${type.comment}';\n\n`
|
||||||
: ""
|
: ""
|
||||||
}`,
|
}`,
|
||||||
)
|
)
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
return `${enumStatements}${typeStatements}${diagram.tables
|
return `${enumStatements}${enumStatements.trim() !== "" ? `\n${typeStatements}` : typeStatements}${diagram.tables
|
||||||
.map(
|
.map(
|
||||||
(table) =>
|
(table) =>
|
||||||
`CREATE TABLE "${table.name}" (\n${table.fields
|
`CREATE TABLE "${table.name}" (\n${table.fields
|
||||||
@ -32,7 +32,9 @@ export function toPostgres(diagram) {
|
|||||||
`${exportFieldComment(field.comment)}\t"${
|
`${exportFieldComment(field.comment)}\t"${
|
||||||
field.name
|
field.name
|
||||||
}" ${field.type}${
|
}" ${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.isArray ? " ARRAY" : ""}${field.notNull ? " NOT NULL" : ""}${field.unique ? " UNIQUE" : ""}${
|
||||||
field.increment ? " GENERATED BY DEFAULT AS IDENTITY" : ""
|
field.increment ? " GENERATED BY DEFAULT AS IDENTITY" : ""
|
||||||
}${
|
}${
|
||||||
@ -53,7 +55,7 @@ export function toPostgres(diagram) {
|
|||||||
.map((f) => `"${f.name}"`)
|
.map((f) => `"${f.name}"`)
|
||||||
.join(", ")})`
|
.join(", ")})`
|
||||||
: ""
|
: ""
|
||||||
}\n);\n${
|
}\n);${
|
||||||
table.comment.trim() !== ""
|
table.comment.trim() !== ""
|
||||||
? `\nCOMMENT ON TABLE "${table.name}" IS '${table.comment}';\n`
|
? `\nCOMMENT ON TABLE "${table.name}" IS '${table.comment}';\n`
|
||||||
: ""
|
: ""
|
||||||
@ -74,10 +76,10 @@ export function toPostgres(diagram) {
|
|||||||
)
|
)
|
||||||
.join("\n")}\n`,
|
.join("\n")}\n`,
|
||||||
)
|
)
|
||||||
.join("\n")}\n${diagram.references
|
.join("\n")}${diagram.references
|
||||||
.map(
|
.map(
|
||||||
(r) =>
|
(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
|
diagram.tables[r.startTableId].fields[r.startFieldId].name
|
||||||
}") REFERENCES "${diagram.tables[r.endTableId].name}"("${
|
}") REFERENCES "${diagram.tables[r.endTableId].name}"("${
|
||||||
diagram.tables[r.endTableId].fields[r.endFieldId].name
|
diagram.tables[r.endTableId].fields[r.endFieldId].name
|
||||||
|
Loading…
Reference in New Issue
Block a user