Skip to content

Free, simple, and intuitive online database diagram editor and SQL generator.

Fix error when field.values is undefined and add it to issues

1ilit81792a524315
diff --git a/src/components/table.jsx b/src/components/table.jsx
index ddb166ae..84ab2f30 100644
--- a/src/components/table.jsx
+++ b/src/components/table.jsx
@@ -377,11 +377,26 @@ export default function Table(props) {
(value === "INT" ||
value === "BIGINT" ||
value === "SMALLINT");
- updateField(props.tableData.id, j, {
- type: value,
- length: value === "VARCHAR" ? 255 : "",
- increment: incr,
- });
+ if (value === "ENUM" || value === "SET") {
+ updateField(props.tableData.id, j, {
+ type: value,
+ values: [],
+ increment: incr,
+ });
+ } else if (value === "VARCHAR") {
+ updateField(props.tableData.id, j, {
+ type: value,
+ length: 255,
+ increment: incr,
+ });
+ } else {
+ updateField(props.tableData.id, j, {
+ type: value,
+ increment: incr,
+ length: "",
+ values: [],
+ });
+ }
}}
></Select>
</Col>
@@ -1102,7 +1117,6 @@ export default function Table(props) {
type: "",
default: "",
check: "",
- length: "",
primary: false,
unique: false,
notNull: false,
diff --git a/src/components/table_overview.jsx b/src/components/table_overview.jsx
index b9fe799e..ca0fb235 100644
--- a/src/components/table_overview.jsx
+++ b/src/components/table_overview.jsx
@@ -223,11 +223,26 @@ export default function TableOverview(props) {
(value === "INT" ||
value === "BIGINT" ||
value === "SMALLINT");
- updateField(i, j, {
- type: value,
- length: value === "VARCHAR" ? 255 : "",
- increment: incr,
- });
+ if (value === "ENUM" || value === "SET") {
+ updateField(i, j, {
+ type: value,
+ values: [],
+ increment: incr,
+ });
+ } else if (value === "VARCHAR") {
+ updateField(i, j, {
+ type: value,
+ length: 255,
+ increment: incr,
+ });
+ } else {
+ updateField(i, j, {
+ type: value,
+ increment: incr,
+ length: "",
+ values: [],
+ });
+ }
}}
></Select>
</Col>
@@ -975,7 +990,6 @@ export default function TableOverview(props) {
default: "",
check: "",
primary: false,
- length: "",
unique: false,
notNull: false,
increment: false,
diff --git a/src/pages/editor.jsx b/src/pages/editor.jsx
index 6778ead0..9b038592 100644
--- a/src/pages/editor.jsx
+++ b/src/pages/editor.jsx
@@ -95,7 +95,6 @@ export default function Editor(props) {
unique: true,
notNull: true,
increment: true,
- length: "",
comment: "",
id: 0,
},
diff --git a/src/utils/index.js b/src/utils/index.js
index f00e645e..2e20b3e5 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -59,7 +59,7 @@ function jsonToSQL(obj) {
`${field.comment === "" ? "" : `\t-- ${field.comment}\n`}\t\`${
field.name
}\` ${field.type}${
- field.length !== ""
+ field.type === "VARCHAR"
? `(${field.length})`
: field.type === "ENUM" || field.type === "SET"
? `(${field.values.map((v) => `"${v}"`).join(", ")})`
@@ -142,6 +142,12 @@ function validateDiagram(diagram) {
}
if (field.type === "") {
issues.push(`Empty field type in table "${table.name}"`);
+ } else if (field.type === "ENUM" || field.type === "SET") {
+ if (!field.values || field.values.length === 0) {
+ issues.push(
+ `"${field.name}" field of table "${table.name}" is of type ${field.type} but values have been specified`
+ );
+ }
}
if (duplicateFieldNames[field.name]) {
issues.push(`Duplicate table fields in table "${table.name}"`);