Skip to content

Commit a62721b

Browse files
authored
Fix mssql export to have types with correct sizes (#496)
1 parent 7ca34d8 commit a62721b

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/utils/exportSQL/mssql.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { parseDefault, escapeQuotes } from "./shared";
22

33
import { dbToTypes } from "../../data/datatypes";
4+
import { DB } from "../../data/constants";
45

56
function generateAddExtendedPropertySQL(value, level1name, level2name = null) {
67
if (!value || value.trim() === "") {
@@ -34,23 +35,25 @@ export function toMSSQL(diagram) {
3435
const tablesSql = diagram.tables
3536
.map((table) => {
3637
const fieldsSql = table.fields
37-
.map(
38-
(field) =>
39-
`\t[${field.name}] ${field.type}${field.size && `(${field.size})`}${
40-
field.notNull ? " NOT NULL" : ""
41-
}${field.increment ? " IDENTITY" : ""}${
42-
field.unique ? " UNIQUE" : ""
43-
}${
44-
field.default !== ""
45-
? ` DEFAULT ${parseDefault(field, diagram.database)}`
46-
: ""
47-
}${
48-
field.check === "" ||
49-
!dbToTypes[diagram.database][field.type].hasCheck
50-
? ""
51-
: ` CHECK(${field.check})`
52-
}`,
53-
)
38+
.map((field) => {
39+
const typeMetaData = dbToTypes[DB.MSSQL][field.type.toUpperCase()];
40+
const isSized = typeMetaData.isSized || typeMetaData.hasPrecision;
41+
42+
return `\t[${field.name}] ${field.type}${field.size && isSized ? `(${field.size})` : ""}${
43+
field.notNull ? " NOT NULL" : ""
44+
}${field.increment ? " IDENTITY" : ""}${
45+
field.unique ? " UNIQUE" : ""
46+
}${
47+
field.default !== ""
48+
? ` DEFAULT ${parseDefault(field, diagram.database)}`
49+
: ""
50+
}${
51+
field.check === "" ||
52+
!dbToTypes[diagram.database][field.type].hasCheck
53+
? ""
54+
: ` CHECK(${field.check})`
55+
}`;
56+
})
5457
.join(",\n");
5558

5659
const primaryKeys = table.fields.filter((f) => f.primary);

0 commit comments

Comments
 (0)