Merge branch 'drawdb-io:main' into rtl-fix

This commit is contained in:
Tasnim Tantawi 2024-08-05 10:15:37 +03:00 committed by GitHub
commit 048704f572
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 94 additions and 6 deletions

3
.github/FUNDING.yml vendored
View File

@ -1 +1,2 @@
open_collective: drawdb
open_collective: drawdb
buy_me_a_coffee: drawdb

View File

@ -23,6 +23,7 @@ import {
} from "../../hooks";
import { useTranslation } from "react-i18next";
import { useEventListener } from "usehooks-ts";
import { areFieldsCompatible } from "../../utils/utils";
export default function Canvas() {
const { t } = useTranslation();
@ -34,7 +35,8 @@ export default function Canvas() {
pointer,
} = canvasContextValue;
const { tables, updateTable, relationships, addRelationship } = useDiagram();
const { tables, updateTable, relationships, addRelationship, database } =
useDiagram();
const { areas, updateArea } = useAreas();
const { notes, updateNote } = useNotes();
const { layout } = useLayout();
@ -399,8 +401,11 @@ export default function Canvas() {
if (hoveredTable.tableId < 0) return;
if (hoveredTable.field < 0) return;
if (
tables[linkingLine.startTableId].fields[linkingLine.startFieldId].type !==
tables[hoveredTable.tableId].fields[hoveredTable.field].type
!areFieldsCompatible(
database,
tables[linkingLine.startTableId].fields[linkingLine.startFieldId],
tables[hoveredTable.tableId].fields[hoveredTable.field],
)
) {
Toast.info(t("cannot_connect"));
return;

View File

@ -299,6 +299,44 @@ export default function FieldDetails({ data, tid, index }) {
/>
</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>
<TextArea
className="my-2"

View File

@ -13,6 +13,7 @@ export const databases = new Proxy(
label: DB.MYSQL,
image: mysqlImage,
hasTypes: false,
hasUnsignedTypes: true,
},
[DB.POSTGRES]: {
name: "PostgreSQL",
@ -33,6 +34,7 @@ export const databases = new Proxy(
label: DB.MARIADB,
image: mariadbImage,
hasTypes: false,
hasUnsignedTypes: true,
},
[DB.MSSQL]: {
name: "MSSQL",

View File

@ -279,6 +279,7 @@ const mysqlTypesBase = {
isSized: false,
hasPrecision: false,
canIncrement: true,
signed: true,
},
SMALLINT: {
type: "SMALLINT",
@ -289,6 +290,7 @@ const mysqlTypesBase = {
isSized: false,
hasPrecision: false,
canIncrement: true,
signed: true,
},
MEDIUMINT: {
type: "MEDIUMINT",
@ -299,6 +301,7 @@ const mysqlTypesBase = {
isSized: false,
hasPrecision: false,
canIncrement: true,
signed: true,
},
INTEGER: {
type: "INTEGER",
@ -309,6 +312,7 @@ const mysqlTypesBase = {
isSized: false,
hasPrecision: false,
canIncrement: true,
signed: true,
},
BIGINT: {
type: "BIGINT",
@ -319,6 +323,7 @@ const mysqlTypesBase = {
isSized: false,
hasPrecision: false,
canIncrement: true,
signed: true,
},
DECIMAL: {
type: "DECIMAL",
@ -698,6 +703,7 @@ const postgresTypesBase = {
isSized: false,
hasPrecision: false,
canIncrement: true,
compatibleWith: ["SMALLSERIAL", "SERIAL", "BIGSERIAL", "INTEGER", "BIGINT"],
},
INTEGER: {
type: "INTEGER",
@ -708,6 +714,13 @@ const postgresTypesBase = {
isSized: false,
hasPrecision: false,
canIncrement: true,
compatibleWith: [
"SMALLSERIAL",
"SERIAL",
"BIGSERIAL",
"SMALLINT",
"BIGINT",
],
},
BIGINT: {
type: "BIGINT",
@ -718,6 +731,13 @@ const postgresTypesBase = {
isSized: false,
hasPrecision: false,
canIncrement: true,
compatibleWith: [
"SMALLSERIAL",
"SERIAL",
"BIGSERIAL",
"INTEGER",
"SMALLINT",
],
},
DECIMAL: {
type: "DECIMAL",
@ -763,6 +783,7 @@ const postgresTypesBase = {
hasCheck: true,
isSized: false,
hasPrecision: false,
compatibleWith: ["INTEGER", "SERIAL", "BIGSERIAL", "SMALLINT", "BIGINT"],
},
SERIAL: {
type: "SERIAL",
@ -772,6 +793,13 @@ const postgresTypesBase = {
hasCheck: true,
isSized: false,
hasPrecision: false,
compatibleWith: [
"INTEGER",
"SMALLSERIAL",
"BIGSERIAL",
"SMALLINT",
"BIGINT",
],
},
BIGSERIAL: {
type: "BIGSERIAL",
@ -781,6 +809,7 @@ const postgresTypesBase = {
hasCheck: true,
isSized: false,
hasPrecision: false,
compatibleWith: ["INTEGER", "SERIAL", "SMALLSERIAL", "SMALLINT", "BIGINT"],
},
MONEY: {
type: "MONEY",

View File

@ -235,6 +235,7 @@ const en = {
declare_array: "Declare array",
empty_index_name: "Declared an index with no name in table '{{tableName}}'",
didnt_find_diagram: "Oops! Didn't find the diagram.",
unsigned: "Unsigned",
},
};

View File

@ -13,7 +13,7 @@ export function toMariaDB(diagram) {
(field) =>
`${exportFieldComment(field.comment)}\t\`${
field.name
}\` ${field.type}${field.notNull ? " NOT NULL" : ""}${
}\` ${field.type}${field.unsigned ? " UNSIGNED" : ""}${field.notNull ? " NOT NULL" : ""}${
field.increment ? " AUTO_INCREMENT" : ""
}${field.unique ? " UNIQUE" : ""}${
field.default !== ""

View File

@ -13,7 +13,7 @@ export function toMySQL(diagram) {
(field) =>
`${exportFieldComment(field.comment)}\t\`${
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.increment ? " AUTO_INCREMENT" : ""

View File

@ -1,3 +1,5 @@
import { dbToTypes } from "../data/datatypes";
export function dataURItoBlob(dataUrl) {
const byteString = atob(dataUrl.split(",")[1]);
const mimeString = dataUrl.split(",")[0].split(":")[1].split(";")[0];
@ -34,3 +36,13 @@ export function isKeyword(str) {
export function isFunction(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;
}