Skip to content

Commit aab7099

Browse files
committed
fix(oracle): correct datatype mapping and size handling in Oracle exporter
1 parent 9fe82b1 commit aab7099

File tree

2 files changed

+88
-23
lines changed

2 files changed

+88
-23
lines changed

src/data/datatypes.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,77 @@ const oraclesqlTypesBase = {
22012201
defaultSize: 255,
22022202
hasQuotes: false,
22032203
},
2204+
INT: {
2205+
type: "NUMBER",
2206+
color: intColor,
2207+
checkDefault: (field) => intRegex.test(field.default),
2208+
hasCheck: true,
2209+
isSized: false,
2210+
hasPrecision: true,
2211+
canIncrement: false,
2212+
},
2213+
SMALLINT: {
2214+
type: "NUMBER",
2215+
color: intColor,
2216+
checkDefault: (field) => intRegex.test(field.default),
2217+
hasCheck: true,
2218+
isSized: false,
2219+
hasPrecision: true,
2220+
canIncrement: false,
2221+
},
2222+
BIGINT: {
2223+
type: "NUMBER",
2224+
color: intColor,
2225+
checkDefault: (field) => intRegex.test(field.default),
2226+
hasCheck: true,
2227+
isSized: false,
2228+
hasPrecision: true,
2229+
canIncrement: false,
2230+
},
2231+
DECIMAL: {
2232+
type: "NUMBER",
2233+
color: decimalColor,
2234+
checkDefault: (field) => doubleRegex.test(field.default),
2235+
hasCheck: true,
2236+
isSized: false,
2237+
hasPrecision: true,
2238+
},
2239+
DOUBLE: {
2240+
type: "BINARY_DOUBLE",
2241+
color: decimalColor,
2242+
checkDefault: (field) => doubleRegex.test(field.default),
2243+
hasCheck: true,
2244+
isSized: false,
2245+
hasPrecision: true,
2246+
},
2247+
VARCHAR: {
2248+
type: "VARCHAR2",
2249+
color: stringColor,
2250+
checkDefault: (field) => field.default.length <= field.size,
2251+
hasCheck: true,
2252+
isSized: true,
2253+
hasPrecision: false,
2254+
defaultSize: 255,
2255+
hasQuotes: true,
2256+
},
2257+
TEXT: {
2258+
type: "CLOB",
2259+
color: stringColor,
2260+
checkDefault: (field) => true,
2261+
hasCheck: false,
2262+
isSized: false,
2263+
hasPrecision: false,
2264+
hasQuotes: true,
2265+
},
2266+
ENUM: {
2267+
type: "ENUM",
2268+
color: enumSetColor,
2269+
checkDefault: (field) => field.values.includes(field.default),
2270+
hasCheck: false,
2271+
isSized: false,
2272+
hasPrecision: false,
2273+
hasQuotes: true,
2274+
},
22042275
};
22052276

22062277
export const oraclesqlTypes = new Proxy(oraclesqlTypesBase, {

src/utils/exportSQL/oraclesql.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,25 @@ import { parseDefault } from "./shared";
44
export function toOracleSQL(diagram) {
55
return `${diagram.tables
66
.map(
7-
(table) =>
7+
(table) =>
88
`${
99
table.comment === "" ? "" : `/* ${table.comment} */\n`
1010
}CREATE TABLE "${table.name}" (\n${table.fields
11-
.map(
12-
(field) =>
13-
`${field.comment === "" ? "" : `\t-- ${field.comment}\n`}\t"${
14-
field.name
15-
}" ${field.type}${
16-
field.size !== undefined && field.size !== ""
17-
? "(" + field.size + ")"
18-
: ""
19-
}${field.notNull ? " NOT NULL" : ""}${
20-
field.increment ? " GENERATED ALWAYS AS IDENTITY" : ""
21-
}${field.unique ? " UNIQUE" : ""}${
22-
field.default !== ""
23-
? ` DEFAULT ${parseDefault(field, diagram.database)}`
24-
: ""
25-
}${
26-
field.check === "" ||
27-
!dbToTypes[diagram.database][field.type].hasCheck
28-
? ""
29-
: ` CHECK(${field.check})`
30-
}${field.comment ? ` -- ${field.comment}` : ""}`,
31-
)
11+
.map((field) => {
12+
const typeInfo = dbToTypes[diagram.database][field.type] || { type: field.type };
13+
const oracleType = typeInfo.type;
14+
return `${field.comment === "" ? "" : `\t-- ${field.comment}\n`}\t"${
15+
field.name
16+
}" ${oracleType}${
17+
typeInfo.isSized && field.size ? `(${field.size})` : ""
18+
}${field.notNull ? " NOT NULL" : ""}${field.increment ? " GENERATED ALWAYS AS IDENTITY" : ""}${field.unique ? " UNIQUE" : ""}${
19+
field.default !== "" ? ` DEFAULT ${parseDefault(field, diagram.database)}` : ""
20+
}${
21+
field.check === "" || !typeInfo.hasCheck
22+
? ""
23+
: ` CHECK(${field.check})`
24+
}${field.comment ? ` -- ${field.comment}` : ""}`;
25+
})
3226
.join(",\n")}${
3327
table.fields.filter((f) => f.primary).length > 0
3428
? `,\n\tPRIMARY KEY(${table.fields
@@ -57,7 +51,7 @@ export function toOracleSQL(diagram) {
5751
startFields.find((f) => f.id === r.startFieldId).name
5852
}") REFERENCES "${endName}" ("${
5953
endFields.find((f) => f.id === r.endFieldId).name
60-
}")\nON UPDATE ${r.updateConstraint.toUpperCase()} ON DELETE ${r.deleteConstraint.toUpperCase()};`;
54+
}")\nON DELETE ${r.deleteConstraint.toUpperCase()};`;
6155
})
6256
.join("\n")}`;
6357
}

0 commit comments

Comments
 (0)