Fix invalid sql after swapping fields (#287)

This commit is contained in:
1ilit
2024-11-02 11:49:42 +04:00
parent cd2627332f
commit 317c3cc9ba
3 changed files with 48 additions and 7 deletions

View File

@@ -14,11 +14,12 @@ import ColorPalette from "../../ColorPicker";
import TableField from "./TableField";
import IndexDetails from "./IndexDetails";
import { useTranslation } from "react-i18next";
import { dbToTypes } from "../../../data/datatypes";
export default function TableInfo({ data }) {
const { t } = useTranslation();
const [indexActiveKey, setIndexActiveKey] = useState("");
const { deleteTable, updateTable, updateField, setRelationships } =
const { deleteTable, updateTable, updateField, setRelationships, database } =
useDiagram();
const { setUndoStack, setRedoStack } = useUndoRedo();
const [editField, setEditField] = useState({});
@@ -106,8 +107,20 @@ export default function TableInfo({ data }) {
const a = data.fields[index];
const b = data.fields[j];
updateField(data.id, index, { ...b, id: index });
updateField(data.id, j, { ...a, id: j });
updateField(data.id, index, {
...b,
...(!dbToTypes[database][b.type].isSized && { size: "" }),
...(!dbToTypes[database][b.type].hasCheck && { check: "" }),
...(dbToTypes[database][b.type].noDefault && { default: "" }),
id: index,
});
updateField(data.id, j, {
...a,
...(!dbToTypes[database][a.type].isSized && { size: "" }),
...(!dbToTypes[database][a.type].hasCheck && { check: "" }),
...(!dbToTypes[database][a.type].noDefault && { default: "" }),
id: j,
});
setRelationships((prev) =>
prev.map((e) => {