Skip to content

Commit

Permalink
Use COMMENT keyword when exporting comments
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilit committed Aug 23, 2024
1 parent 1139ad4 commit 27950ba
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/utils/exportSQL/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,10 @@ export function jsonToMySQL(obj) {
return `${obj.tables
.map(
(table) =>
`${
table.comment === "" ? "" : `/* ${table.comment} */\n`
}CREATE TABLE \`${table.name}\` (\n${table.fields
`CREATE TABLE \`${table.name}\` (\n${table.fields
.map(
(field) =>
`${field.comment === "" ? "" : `\t-- ${field.comment}\n`}\t\`${
`\t\`${
field.name
}\` ${getTypeString(field, obj.database)}${field.notNull ? " NOT NULL" : ""}${
field.increment ? " AUTO_INCREMENT" : ""
Expand Down Expand Up @@ -220,16 +218,16 @@ export function jsonToPostgreSQL(obj) {
.join("\n")}\n);`
);
} else {
return `${
type.comment === "" ? "" : `/**\n${type.comment}\n*/\n`
}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")}`)
.join("\n")}\n);`;
.join(
"\n",
)}\n);\n${type.comment != "" ? `\nCOMMENT ON TYPE ${type.name} IS '${type.comment}';\n` : ""}`;
}
})}\n${obj.tables
.map(
(table) =>
`${table.comment === "" ? "" : `/**\n${table.comment}\n*/\n`}${
`${
table.fields.filter((f) => f.type === "ENUM" || f.type === "SET")
.length > 0
? `${table.fields
Expand Down Expand Up @@ -265,7 +263,13 @@ export function jsonToPostgreSQL(obj) {
.map((f) => `"${f.name}"`)
.join(", ")})`
: ""
}\n);\n${table.indices
}\n);\n${table.comment != "" ? `\nCOMMENT ON TABLE ${table.name} IS '${table.comment}';\n` : ""}${table.fields
.map((field) =>
field.comment.trim() !== ""
? `COMMENT ON COLUMN ${table.name}.${field.name} IS '${field.comment}';\n`
: "",
)
.join("")}\n${table.indices
.map(
(i) =>
`CREATE ${i.unique ? "UNIQUE " : ""}INDEX "${
Expand Down Expand Up @@ -381,12 +385,10 @@ export function jsonToMariaDB(obj) {
return `${obj.tables
.map(
(table) =>
`${
table.comment === "" ? "" : `/* ${table.comment} */\n`
}CREATE OR REPLACE TABLE \`${table.name}\` (\n${table.fields
`CREATE OR REPLACE TABLE \`${table.name}\` (\n${table.fields
.map(
(field) =>
`${field.comment === "" ? "" : `\t-- ${field.comment}\n`}\t\`${
`\t\`${
field.name
}\` ${getTypeString(field, obj.database)}${field.notNull ? " NOT NULL" : ""}${
field.increment ? " AUTO_INCREMENT" : ""
Expand All @@ -405,7 +407,7 @@ export function jsonToMariaDB(obj) {
)}', \`${field.name}\`))`
: ""
: ` CHECK(${field.check})`
}`,
}${field.comment ? ` COMMENT '${field.comment}'` : ""}`,
)
.join(",\n")}${
table.fields.filter((f) => f.primary).length > 0
Expand All @@ -414,7 +416,7 @@ export function jsonToMariaDB(obj) {
.map((f) => `\`${f.name}\``)
.join(", ")})`
: ""
}\n);${`\n${table.indices
}\n)${table.comment ? ` COMMENT='${table.comment}'` : ""};${`\n${table.indices
.map(
(i) =>
`CREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${
Expand Down

0 comments on commit 27950ba

Please sign in to comment.