diff --git a/src/components/EditorHeader/ControlPanel.jsx b/src/components/EditorHeader/ControlPanel.jsx index e4c0d4b..e064cf7 100644 --- a/src/components/EditorHeader/ControlPanel.jsx +++ b/src/components/EditorHeader/ControlPanel.jsx @@ -55,6 +55,7 @@ import { useTypes, useNotes, useAreas, + useEnums, } from "../../hooks"; import { enterFullscreen } from "../../utils/fullscreen"; import { dataURItoBlob } from "../../utils/utils"; @@ -99,6 +100,7 @@ export default function ControlPanel({ deleteRelationship, database, } = useTables(); + const { enums } = useEnums(); const { types, addType, deleteType, updateType, setTypes } = useTypes(); const { notes, setNotes, updateNote, addNote, deleteNote } = useNotes(); const { areas, setAreas, updateArea, addArea, deleteArea } = useAreas(); @@ -871,6 +873,7 @@ export default function ControlPanel({ references: relationships, types: types, database: database, + enums: enums, }); setExportData((prev) => ({ ...prev, diff --git a/src/data/datatypes.js b/src/data/datatypes.js index 7e2dae1..47e1702 100644 --- a/src/data/datatypes.js +++ b/src/data/datatypes.js @@ -268,7 +268,7 @@ export const defaultTypes = new Proxy(defaultTypesBase, { get: (target, prop) => (prop in target ? target[prop] : {}), }); -export const mysqlTypesBase = { +const mysqlTypesBase = { TINYINT: { type: "TINYINT", checkDefault: (field) => { @@ -687,7 +687,7 @@ export const mysqlTypes = new Proxy(mysqlTypesBase, { get: (target, prop) => (prop in target ? target[prop] : {}), }); -export const postgresTypesBase = { +const postgresTypesBase = { SMALLINT: { type: "SMALLINT", checkDefault: (field) => { @@ -912,14 +912,6 @@ export const postgresTypesBase = { hasPrecision: false, hasQuotes: false, }, - ENUM: { - type: "ENUM", - checkDefault: (field) => true, - hasCheck: false, - isSized: false, - hasPrecision: false, - hasQuotes: true, - }, POINT: { type: "POINT", checkDefault: (field) => /^\(\d+,\d+\)$/.test(field.default), @@ -1110,7 +1102,7 @@ export const postgresTypes = new Proxy(postgresTypesBase, { get: (target, prop) => (prop in target ? target[prop] : {}), }); -export const sqliteTypesBase = { +const sqliteTypesBase = { INTEGER: { type: "INTEGER", checkDefault: (field) => { @@ -1246,7 +1238,7 @@ export const sqliteTypes = new Proxy(sqliteTypesBase, { get: (target, prop) => (prop in target ? target[prop] : {}), }); -export const mssqlTypesBase = { +const mssqlTypesBase = { BIGINT: { type: "", checkDefault: (field) => {} }, INTEGER: { type: "", checkDefault: (field) => {} }, SMALLINT: { type: "", checkDefault: (field) => {} }, @@ -1296,5 +1288,5 @@ const dbToTypesBase = { }; export const dbToTypes = new Proxy(dbToTypesBase, { - get: (target, prop) => (prop in target ? target[prop] : []), + get: (target, prop) => (prop in target ? target[prop] : {}), }); diff --git a/src/utils/exportSQL/postgres.js b/src/utils/exportSQL/postgres.js index caf3852..7e3846a 100644 --- a/src/utils/exportSQL/postgres.js +++ b/src/utils/exportSQL/postgres.js @@ -2,7 +2,14 @@ import { dbToTypes } from "../../data/datatypes"; import { parseDefault } from "./shared"; export function toPostgres(diagram) { - return `${diagram.types.map((type) => { + const enumStatements = diagram.enums + .map( + (e) => + `CREATE TYPE "${e.name}" AS ENUM (\n${e.values.map((v) => `\t'${v}'`).join("\n")}\n);`, + ) + .join("\n"); + + return `${enumStatements}\n${diagram.types.map((type) => { const typeStatements = type.fields .filter((f) => f.type === "ENUM" || f.type === "SET") .map(