Merge branch 'drawdb-io:main' into rtl-fix
This commit is contained in:
commit
048704f572
3
.github/FUNDING.yml
vendored
3
.github/FUNDING.yml
vendored
@ -1 +1,2 @@
|
|||||||
open_collective: drawdb
|
open_collective: drawdb
|
||||||
|
buy_me_a_coffee: drawdb
|
@ -23,6 +23,7 @@ import {
|
|||||||
} from "../../hooks";
|
} from "../../hooks";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useEventListener } from "usehooks-ts";
|
import { useEventListener } from "usehooks-ts";
|
||||||
|
import { areFieldsCompatible } from "../../utils/utils";
|
||||||
|
|
||||||
export default function Canvas() {
|
export default function Canvas() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -34,7 +35,8 @@ export default function Canvas() {
|
|||||||
pointer,
|
pointer,
|
||||||
} = canvasContextValue;
|
} = canvasContextValue;
|
||||||
|
|
||||||
const { tables, updateTable, relationships, addRelationship } = useDiagram();
|
const { tables, updateTable, relationships, addRelationship, database } =
|
||||||
|
useDiagram();
|
||||||
const { areas, updateArea } = useAreas();
|
const { areas, updateArea } = useAreas();
|
||||||
const { notes, updateNote } = useNotes();
|
const { notes, updateNote } = useNotes();
|
||||||
const { layout } = useLayout();
|
const { layout } = useLayout();
|
||||||
@ -399,8 +401,11 @@ export default function Canvas() {
|
|||||||
if (hoveredTable.tableId < 0) return;
|
if (hoveredTable.tableId < 0) return;
|
||||||
if (hoveredTable.field < 0) return;
|
if (hoveredTable.field < 0) return;
|
||||||
if (
|
if (
|
||||||
tables[linkingLine.startTableId].fields[linkingLine.startFieldId].type !==
|
!areFieldsCompatible(
|
||||||
tables[hoveredTable.tableId].fields[hoveredTable.field].type
|
database,
|
||||||
|
tables[linkingLine.startTableId].fields[linkingLine.startFieldId],
|
||||||
|
tables[hoveredTable.tableId].fields[hoveredTable.field],
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
Toast.info(t("cannot_connect"));
|
Toast.info(t("cannot_connect"));
|
||||||
return;
|
return;
|
||||||
|
@ -299,6 +299,44 @@ export default function FieldDetails({ data, tid, index }) {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{databases[database].hasUnsignedTypes &&
|
||||||
|
dbToTypes[database][data.type].signed && (
|
||||||
|
<div className="flex justify-between items-center my-3">
|
||||||
|
<div className="font-medium">{t("Unsigned")}</div>
|
||||||
|
<Checkbox
|
||||||
|
value="unsigned"
|
||||||
|
checked={data.unsigned}
|
||||||
|
onChange={(checkedValues) => {
|
||||||
|
setUndoStack((prev) => [
|
||||||
|
...prev,
|
||||||
|
{
|
||||||
|
action: Action.EDIT,
|
||||||
|
element: ObjectType.TABLE,
|
||||||
|
component: "field",
|
||||||
|
tid: tid,
|
||||||
|
fid: index,
|
||||||
|
undo: {
|
||||||
|
[checkedValues.target.value]:
|
||||||
|
!checkedValues.target.checked,
|
||||||
|
},
|
||||||
|
redo: {
|
||||||
|
[checkedValues.target.value]:
|
||||||
|
checkedValues.target.checked,
|
||||||
|
},
|
||||||
|
message: t("edit_table", {
|
||||||
|
tableName: tables[tid].name,
|
||||||
|
extra: "[field]",
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
setRedoStack([]);
|
||||||
|
updateField(tid, index, {
|
||||||
|
unsigned: checkedValues.target.checked,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="font-semibold">{t("comment")}</div>
|
<div className="font-semibold">{t("comment")}</div>
|
||||||
<TextArea
|
<TextArea
|
||||||
className="my-2"
|
className="my-2"
|
||||||
|
@ -13,6 +13,7 @@ export const databases = new Proxy(
|
|||||||
label: DB.MYSQL,
|
label: DB.MYSQL,
|
||||||
image: mysqlImage,
|
image: mysqlImage,
|
||||||
hasTypes: false,
|
hasTypes: false,
|
||||||
|
hasUnsignedTypes: true,
|
||||||
},
|
},
|
||||||
[DB.POSTGRES]: {
|
[DB.POSTGRES]: {
|
||||||
name: "PostgreSQL",
|
name: "PostgreSQL",
|
||||||
@ -33,6 +34,7 @@ export const databases = new Proxy(
|
|||||||
label: DB.MARIADB,
|
label: DB.MARIADB,
|
||||||
image: mariadbImage,
|
image: mariadbImage,
|
||||||
hasTypes: false,
|
hasTypes: false,
|
||||||
|
hasUnsignedTypes: true,
|
||||||
},
|
},
|
||||||
[DB.MSSQL]: {
|
[DB.MSSQL]: {
|
||||||
name: "MSSQL",
|
name: "MSSQL",
|
||||||
|
@ -279,6 +279,7 @@ const mysqlTypesBase = {
|
|||||||
isSized: false,
|
isSized: false,
|
||||||
hasPrecision: false,
|
hasPrecision: false,
|
||||||
canIncrement: true,
|
canIncrement: true,
|
||||||
|
signed: true,
|
||||||
},
|
},
|
||||||
SMALLINT: {
|
SMALLINT: {
|
||||||
type: "SMALLINT",
|
type: "SMALLINT",
|
||||||
@ -289,6 +290,7 @@ const mysqlTypesBase = {
|
|||||||
isSized: false,
|
isSized: false,
|
||||||
hasPrecision: false,
|
hasPrecision: false,
|
||||||
canIncrement: true,
|
canIncrement: true,
|
||||||
|
signed: true,
|
||||||
},
|
},
|
||||||
MEDIUMINT: {
|
MEDIUMINT: {
|
||||||
type: "MEDIUMINT",
|
type: "MEDIUMINT",
|
||||||
@ -299,6 +301,7 @@ const mysqlTypesBase = {
|
|||||||
isSized: false,
|
isSized: false,
|
||||||
hasPrecision: false,
|
hasPrecision: false,
|
||||||
canIncrement: true,
|
canIncrement: true,
|
||||||
|
signed: true,
|
||||||
},
|
},
|
||||||
INTEGER: {
|
INTEGER: {
|
||||||
type: "INTEGER",
|
type: "INTEGER",
|
||||||
@ -309,6 +312,7 @@ const mysqlTypesBase = {
|
|||||||
isSized: false,
|
isSized: false,
|
||||||
hasPrecision: false,
|
hasPrecision: false,
|
||||||
canIncrement: true,
|
canIncrement: true,
|
||||||
|
signed: true,
|
||||||
},
|
},
|
||||||
BIGINT: {
|
BIGINT: {
|
||||||
type: "BIGINT",
|
type: "BIGINT",
|
||||||
@ -319,6 +323,7 @@ const mysqlTypesBase = {
|
|||||||
isSized: false,
|
isSized: false,
|
||||||
hasPrecision: false,
|
hasPrecision: false,
|
||||||
canIncrement: true,
|
canIncrement: true,
|
||||||
|
signed: true,
|
||||||
},
|
},
|
||||||
DECIMAL: {
|
DECIMAL: {
|
||||||
type: "DECIMAL",
|
type: "DECIMAL",
|
||||||
@ -698,6 +703,7 @@ const postgresTypesBase = {
|
|||||||
isSized: false,
|
isSized: false,
|
||||||
hasPrecision: false,
|
hasPrecision: false,
|
||||||
canIncrement: true,
|
canIncrement: true,
|
||||||
|
compatibleWith: ["SMALLSERIAL", "SERIAL", "BIGSERIAL", "INTEGER", "BIGINT"],
|
||||||
},
|
},
|
||||||
INTEGER: {
|
INTEGER: {
|
||||||
type: "INTEGER",
|
type: "INTEGER",
|
||||||
@ -708,6 +714,13 @@ const postgresTypesBase = {
|
|||||||
isSized: false,
|
isSized: false,
|
||||||
hasPrecision: false,
|
hasPrecision: false,
|
||||||
canIncrement: true,
|
canIncrement: true,
|
||||||
|
compatibleWith: [
|
||||||
|
"SMALLSERIAL",
|
||||||
|
"SERIAL",
|
||||||
|
"BIGSERIAL",
|
||||||
|
"SMALLINT",
|
||||||
|
"BIGINT",
|
||||||
|
],
|
||||||
},
|
},
|
||||||
BIGINT: {
|
BIGINT: {
|
||||||
type: "BIGINT",
|
type: "BIGINT",
|
||||||
@ -718,6 +731,13 @@ const postgresTypesBase = {
|
|||||||
isSized: false,
|
isSized: false,
|
||||||
hasPrecision: false,
|
hasPrecision: false,
|
||||||
canIncrement: true,
|
canIncrement: true,
|
||||||
|
compatibleWith: [
|
||||||
|
"SMALLSERIAL",
|
||||||
|
"SERIAL",
|
||||||
|
"BIGSERIAL",
|
||||||
|
"INTEGER",
|
||||||
|
"SMALLINT",
|
||||||
|
],
|
||||||
},
|
},
|
||||||
DECIMAL: {
|
DECIMAL: {
|
||||||
type: "DECIMAL",
|
type: "DECIMAL",
|
||||||
@ -763,6 +783,7 @@ const postgresTypesBase = {
|
|||||||
hasCheck: true,
|
hasCheck: true,
|
||||||
isSized: false,
|
isSized: false,
|
||||||
hasPrecision: false,
|
hasPrecision: false,
|
||||||
|
compatibleWith: ["INTEGER", "SERIAL", "BIGSERIAL", "SMALLINT", "BIGINT"],
|
||||||
},
|
},
|
||||||
SERIAL: {
|
SERIAL: {
|
||||||
type: "SERIAL",
|
type: "SERIAL",
|
||||||
@ -772,6 +793,13 @@ const postgresTypesBase = {
|
|||||||
hasCheck: true,
|
hasCheck: true,
|
||||||
isSized: false,
|
isSized: false,
|
||||||
hasPrecision: false,
|
hasPrecision: false,
|
||||||
|
compatibleWith: [
|
||||||
|
"INTEGER",
|
||||||
|
"SMALLSERIAL",
|
||||||
|
"BIGSERIAL",
|
||||||
|
"SMALLINT",
|
||||||
|
"BIGINT",
|
||||||
|
],
|
||||||
},
|
},
|
||||||
BIGSERIAL: {
|
BIGSERIAL: {
|
||||||
type: "BIGSERIAL",
|
type: "BIGSERIAL",
|
||||||
@ -781,6 +809,7 @@ const postgresTypesBase = {
|
|||||||
hasCheck: true,
|
hasCheck: true,
|
||||||
isSized: false,
|
isSized: false,
|
||||||
hasPrecision: false,
|
hasPrecision: false,
|
||||||
|
compatibleWith: ["INTEGER", "SERIAL", "SMALLSERIAL", "SMALLINT", "BIGINT"],
|
||||||
},
|
},
|
||||||
MONEY: {
|
MONEY: {
|
||||||
type: "MONEY",
|
type: "MONEY",
|
||||||
|
@ -235,6 +235,7 @@ const en = {
|
|||||||
declare_array: "Declare array",
|
declare_array: "Declare array",
|
||||||
empty_index_name: "Declared an index with no name in table '{{tableName}}'",
|
empty_index_name: "Declared an index with no name in table '{{tableName}}'",
|
||||||
didnt_find_diagram: "Oops! Didn't find the diagram.",
|
didnt_find_diagram: "Oops! Didn't find the diagram.",
|
||||||
|
unsigned: "Unsigned",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ export function toMariaDB(diagram) {
|
|||||||
(field) =>
|
(field) =>
|
||||||
`${exportFieldComment(field.comment)}\t\`${
|
`${exportFieldComment(field.comment)}\t\`${
|
||||||
field.name
|
field.name
|
||||||
}\` ${field.type}${field.notNull ? " NOT NULL" : ""}${
|
}\` ${field.type}${field.unsigned ? " UNSIGNED" : ""}${field.notNull ? " NOT NULL" : ""}${
|
||||||
field.increment ? " AUTO_INCREMENT" : ""
|
field.increment ? " AUTO_INCREMENT" : ""
|
||||||
}${field.unique ? " UNIQUE" : ""}${
|
}${field.unique ? " UNIQUE" : ""}${
|
||||||
field.default !== ""
|
field.default !== ""
|
||||||
|
@ -13,7 +13,7 @@ export function toMySQL(diagram) {
|
|||||||
(field) =>
|
(field) =>
|
||||||
`${exportFieldComment(field.comment)}\t\`${
|
`${exportFieldComment(field.comment)}\t\`${
|
||||||
field.name
|
field.name
|
||||||
}\` ${field.type}${field.size !== undefined && field.size !== "" ? "(" + field.size + ")" : ""}${
|
}\` ${field.type}${field.unsigned ? " UNSIGNED" : ""}${field.size !== undefined && field.size !== "" ? "(" + field.size + ")" : ""}${
|
||||||
field.notNull ? " NOT NULL" : ""
|
field.notNull ? " NOT NULL" : ""
|
||||||
}${
|
}${
|
||||||
field.increment ? " AUTO_INCREMENT" : ""
|
field.increment ? " AUTO_INCREMENT" : ""
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { dbToTypes } from "../data/datatypes";
|
||||||
|
|
||||||
export function dataURItoBlob(dataUrl) {
|
export function dataURItoBlob(dataUrl) {
|
||||||
const byteString = atob(dataUrl.split(",")[1]);
|
const byteString = atob(dataUrl.split(",")[1]);
|
||||||
const mimeString = dataUrl.split(",")[0].split(":")[1].split(";")[0];
|
const mimeString = dataUrl.split(",")[0].split(":")[1].split(";")[0];
|
||||||
@ -34,3 +36,13 @@ export function isKeyword(str) {
|
|||||||
export function isFunction(str) {
|
export function isFunction(str) {
|
||||||
return /\w+\([^)]*\)$/.test(str);
|
return /\w+\([^)]*\)$/.test(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function areFieldsCompatible(db, field1, field2) {
|
||||||
|
const same = field1.type === field2.type;
|
||||||
|
if (dbToTypes[db][field1.type].compatibleWith) {
|
||||||
|
return (
|
||||||
|
dbToTypes[db][field1.type].compatibleWith.includes(field2.type) || same
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return same;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user