Skip to content

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

Add hasDefault and canIncrement to types

1ilit7953b7fdc00e
diff --git a/src/components/EditorSidePanel/TablesTab/FieldDetails.jsx b/src/components/EditorSidePanel/TablesTab/FieldDetails.jsx
index 35ba97b8..0f10a6a0 100644
--- a/src/components/EditorSidePanel/TablesTab/FieldDetails.jsx
+++ b/src/components/EditorSidePanel/TablesTab/FieldDetails.jsx
@@ -27,13 +27,7 @@ export default function FieldDetails({ data, tid, index }) {
className="my-2"
placeholder={t("default_value")}
value={data.default}
- disabled={
- data.type === "BLOB" ||
- data.type === "JSON" ||
- data.type === "TEXT" ||
- data.type === "UUID" ||
- data.increment
- }
+ disabled={dbToTypes[database][data.type].hasDefault || data.increment}
onChange={(value) => updateField(tid, index, { default: value })}
onFocus={(e) => setEditField({ default: e.target.value })}
onBlur={(e) => {
@@ -236,13 +230,7 @@ export default function FieldDetails({ data, tid, index }) {
<Checkbox
value="increment"
checked={data.increment}
- disabled={
- !(
- data.type === "INT" ||
- data.type === "BIGINT" ||
- data.type === "SMALLINT"
- )
- }
+ disabled={!dbToTypes[database][data.type].canIncrement}
onChange={(checkedValues) => {
setUndoStack((prev) => [
...prev,
diff --git a/src/components/EditorSidePanel/TablesTab/TableField.jsx b/src/components/EditorSidePanel/TablesTab/TableField.jsx
index c5b6ac41..8378b18a 100644
--- a/src/components/EditorSidePanel/TablesTab/TableField.jsx
+++ b/src/components/EditorSidePanel/TablesTab/TableField.jsx
@@ -83,8 +83,7 @@ export default function TableField({ data, tid, index }) {
]);
setRedoStack([]);
const incr =
- data.increment &&
- (value === "INT" || value === "BIGINT" || value === "SMALLINT");
+ data.increment && dbToTypes[database][value].canIncrement;
if (value === "ENUM" || value === "SET") {
updateField(tid, index, {
type: value,
@@ -101,13 +100,7 @@ export default function TableField({ data, tid, index }) {
size: dbToTypes[database][value].defaultSize,
increment: incr,
});
- } else if (
- value === "BLOB" ||
- value === "JSON" ||
- value === "UUID" ||
- value === "TEXT" ||
- incr
- ) {
+ } else if (!dbToTypes[database][value].hasDefault || incr) {
updateField(tid, index, {
type: value,
increment: incr,
diff --git a/src/data/datatypes.js b/src/data/datatypes.js
index f4dae25a..a35937be 100644
--- a/src/data/datatypes.js
+++ b/src/data/datatypes.js
@@ -15,6 +15,7 @@ export const defaultTypes = {
isSized: false,
hasPrecision: false,
defaultSize: null,
+ canIncrement: true,
},
SMALLINT: {
type: "SMALLINT",
@@ -25,6 +26,7 @@ export const defaultTypes = {
isSized: false,
hasPrecision: false,
defaultSize: null,
+ canIncrement: true,
},
BIGINT: {
type: "BIGINT",
@@ -35,6 +37,7 @@ export const defaultTypes = {
hasCheck: true,
hasPrecision: false,
defaultSize: null,
+ canIncrement: true,
},
DECIMAL: {
type: "DECIMAL",
@@ -229,6 +232,7 @@ export const defaultTypes = {
hasCheck: false,
hasPrecision: false,
defaultSize: null,
+ noDefault: true,
},
JSON: {
type: "JSON",
@@ -237,6 +241,7 @@ export const defaultTypes = {
hasCheck: false,
hasPrecision: false,
defaultSize: null,
+ noDefault: true,
},
UUID: {
type: "UUID",
@@ -245,6 +250,7 @@ export const defaultTypes = {
hasCheck: false,
hasPrecision: false,
defaultSize: null,
+ noDefault: true,
},
ENUM: {
type: "ENUM",
@@ -270,6 +276,7 @@ export const defaultTypes = {
isSized: false,
hasPrecision: false,
defaultSize: null,
+ noDefault: true,
},
};
@@ -375,6 +382,7 @@ export const sqliteTypes = {
isSized: false,
hasPrecision: false,
defaultSize: null,
+ canIncrement: true,
},
REAL: {
type: "REAL",
@@ -430,7 +438,8 @@ export const sqliteTypes = {
return field.default.length - 2 <= field.size;
}
return field.default.length <= field.size;
- }, hasCheck: true,
+ },
+ hasCheck: true,
isSized: true,
hasPrecision: false,
defaultSize: 65535,
@@ -443,6 +452,7 @@ export const sqliteTypes = {
hasCheck: false,
hasPrecision: false,
defaultSize: null,
+ noDefault: true,
},
TIME: {
diff --git a/src/utils/importSQL/mysql.js b/src/utils/importSQL/mysql.js
index 505257d4..fb54612f 100644
--- a/src/utils/importSQL/mysql.js
+++ b/src/utils/importSQL/mysql.js
@@ -1,6 +1,7 @@
import { Cardinality, DB } from "../../data/constants";
import { buildSQLFromAST } from "./shared";
+// eslint-disable-next-line no-unused-vars
export function fromMySQL(ast, diagramDb = DB.GENERIC) {
const tables = [];
const relationships = [];