Add hasDefault and canIncrement to types

This commit is contained in:
1ilit 2024-06-14 23:32:58 +03:00
parent e61757f93d
commit 7953b7fdc0
4 changed files with 16 additions and 24 deletions

View File

@ -27,13 +27,7 @@ export default function FieldDetails({ data, tid, index }) {
className="my-2" className="my-2"
placeholder={t("default_value")} placeholder={t("default_value")}
value={data.default} value={data.default}
disabled={ disabled={dbToTypes[database][data.type].hasDefault || data.increment}
data.type === "BLOB" ||
data.type === "JSON" ||
data.type === "TEXT" ||
data.type === "UUID" ||
data.increment
}
onChange={(value) => updateField(tid, index, { default: value })} onChange={(value) => updateField(tid, index, { default: value })}
onFocus={(e) => setEditField({ default: e.target.value })} onFocus={(e) => setEditField({ default: e.target.value })}
onBlur={(e) => { onBlur={(e) => {
@ -236,13 +230,7 @@ export default function FieldDetails({ data, tid, index }) {
<Checkbox <Checkbox
value="increment" value="increment"
checked={data.increment} checked={data.increment}
disabled={ disabled={!dbToTypes[database][data.type].canIncrement}
!(
data.type === "INT" ||
data.type === "BIGINT" ||
data.type === "SMALLINT"
)
}
onChange={(checkedValues) => { onChange={(checkedValues) => {
setUndoStack((prev) => [ setUndoStack((prev) => [
...prev, ...prev,

View File

@ -83,8 +83,7 @@ export default function TableField({ data, tid, index }) {
]); ]);
setRedoStack([]); setRedoStack([]);
const incr = const incr =
data.increment && data.increment && dbToTypes[database][value].canIncrement;
(value === "INT" || value === "BIGINT" || value === "SMALLINT");
if (value === "ENUM" || value === "SET") { if (value === "ENUM" || value === "SET") {
updateField(tid, index, { updateField(tid, index, {
type: value, type: value,
@ -101,13 +100,7 @@ export default function TableField({ data, tid, index }) {
size: dbToTypes[database][value].defaultSize, size: dbToTypes[database][value].defaultSize,
increment: incr, increment: incr,
}); });
} else if ( } else if (!dbToTypes[database][value].hasDefault || incr) {
value === "BLOB" ||
value === "JSON" ||
value === "UUID" ||
value === "TEXT" ||
incr
) {
updateField(tid, index, { updateField(tid, index, {
type: value, type: value,
increment: incr, increment: incr,

View File

@ -15,6 +15,7 @@ export const defaultTypes = {
isSized: false, isSized: false,
hasPrecision: false, hasPrecision: false,
defaultSize: null, defaultSize: null,
canIncrement: true,
}, },
SMALLINT: { SMALLINT: {
type: "SMALLINT", type: "SMALLINT",
@ -25,6 +26,7 @@ export const defaultTypes = {
isSized: false, isSized: false,
hasPrecision: false, hasPrecision: false,
defaultSize: null, defaultSize: null,
canIncrement: true,
}, },
BIGINT: { BIGINT: {
type: "BIGINT", type: "BIGINT",
@ -35,6 +37,7 @@ export const defaultTypes = {
hasCheck: true, hasCheck: true,
hasPrecision: false, hasPrecision: false,
defaultSize: null, defaultSize: null,
canIncrement: true,
}, },
DECIMAL: { DECIMAL: {
type: "DECIMAL", type: "DECIMAL",
@ -229,6 +232,7 @@ export const defaultTypes = {
hasCheck: false, hasCheck: false,
hasPrecision: false, hasPrecision: false,
defaultSize: null, defaultSize: null,
noDefault: true,
}, },
JSON: { JSON: {
type: "JSON", type: "JSON",
@ -237,6 +241,7 @@ export const defaultTypes = {
hasCheck: false, hasCheck: false,
hasPrecision: false, hasPrecision: false,
defaultSize: null, defaultSize: null,
noDefault: true,
}, },
UUID: { UUID: {
type: "UUID", type: "UUID",
@ -245,6 +250,7 @@ export const defaultTypes = {
hasCheck: false, hasCheck: false,
hasPrecision: false, hasPrecision: false,
defaultSize: null, defaultSize: null,
noDefault: true,
}, },
ENUM: { ENUM: {
type: "ENUM", type: "ENUM",
@ -270,6 +276,7 @@ export const defaultTypes = {
isSized: false, isSized: false,
hasPrecision: false, hasPrecision: false,
defaultSize: null, defaultSize: null,
noDefault: true,
}, },
}; };
@ -375,6 +382,7 @@ export const sqliteTypes = {
isSized: false, isSized: false,
hasPrecision: false, hasPrecision: false,
defaultSize: null, defaultSize: null,
canIncrement: true,
}, },
REAL: { REAL: {
type: "REAL", type: "REAL",
@ -430,7 +438,8 @@ export const sqliteTypes = {
return field.default.length - 2 <= field.size; return field.default.length - 2 <= field.size;
} }
return field.default.length <= field.size; return field.default.length <= field.size;
}, hasCheck: true, },
hasCheck: true,
isSized: true, isSized: true,
hasPrecision: false, hasPrecision: false,
defaultSize: 65535, defaultSize: 65535,
@ -443,6 +452,7 @@ export const sqliteTypes = {
hasCheck: false, hasCheck: false,
hasPrecision: false, hasPrecision: false,
defaultSize: null, defaultSize: null,
noDefault: true,
}, },
TIME: { TIME: {

View File

@ -1,6 +1,7 @@
import { Cardinality, DB } from "../../data/constants"; import { Cardinality, DB } from "../../data/constants";
import { buildSQLFromAST } from "./shared"; import { buildSQLFromAST } from "./shared";
// eslint-disable-next-line no-unused-vars
export function fromMySQL(ast, diagramDb = DB.GENERIC) { export function fromMySQL(ast, diagramDb = DB.GENERIC) {
const tables = []; const tables = [];
const relationships = []; const relationships = [];