Add hasDefault and canIncrement to types
This commit is contained in:
parent
e61757f93d
commit
7953b7fdc0
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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: {
|
||||
|
@ -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 = [];
|
||||
|
Loading…
Reference in New Issue
Block a user