mirror of
https://github.com/drawdb-io/drawdb.git
synced 2025-07-18 10:11:24 +00:00
Fix mssql export to have types with correct sizes (#496)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { parseDefault, escapeQuotes } from "./shared";
|
import { parseDefault, escapeQuotes } from "./shared";
|
||||||
|
|
||||||
import { dbToTypes } from "../../data/datatypes";
|
import { dbToTypes } from "../../data/datatypes";
|
||||||
|
import { DB } from "../../data/constants";
|
||||||
|
|
||||||
function generateAddExtendedPropertySQL(value, level1name, level2name = null) {
|
function generateAddExtendedPropertySQL(value, level1name, level2name = null) {
|
||||||
if (!value || value.trim() === "") {
|
if (!value || value.trim() === "") {
|
||||||
@@ -34,23 +35,25 @@ export function toMSSQL(diagram) {
|
|||||||
const tablesSql = diagram.tables
|
const tablesSql = diagram.tables
|
||||||
.map((table) => {
|
.map((table) => {
|
||||||
const fieldsSql = table.fields
|
const fieldsSql = table.fields
|
||||||
.map(
|
.map((field) => {
|
||||||
(field) =>
|
const typeMetaData = dbToTypes[DB.MSSQL][field.type.toUpperCase()];
|
||||||
`\t[${field.name}] ${field.type}${field.size && `(${field.size})`}${
|
const isSized = typeMetaData.isSized || typeMetaData.hasPrecision;
|
||||||
field.notNull ? " NOT NULL" : ""
|
|
||||||
}${field.increment ? " IDENTITY" : ""}${
|
return `\t[${field.name}] ${field.type}${field.size && isSized ? `(${field.size})` : ""}${
|
||||||
field.unique ? " UNIQUE" : ""
|
field.notNull ? " NOT NULL" : ""
|
||||||
}${
|
}${field.increment ? " IDENTITY" : ""}${
|
||||||
field.default !== ""
|
field.unique ? " UNIQUE" : ""
|
||||||
? ` DEFAULT ${parseDefault(field, diagram.database)}`
|
}${
|
||||||
: ""
|
field.default !== ""
|
||||||
}${
|
? ` DEFAULT ${parseDefault(field, diagram.database)}`
|
||||||
field.check === "" ||
|
: ""
|
||||||
!dbToTypes[diagram.database][field.type].hasCheck
|
}${
|
||||||
? ""
|
field.check === "" ||
|
||||||
: ` CHECK(${field.check})`
|
!dbToTypes[diagram.database][field.type].hasCheck
|
||||||
}`,
|
? ""
|
||||||
)
|
: ` CHECK(${field.check})`
|
||||||
|
}`;
|
||||||
|
})
|
||||||
.join(",\n");
|
.join(",\n");
|
||||||
|
|
||||||
const primaryKeys = table.fields.filter((f) => f.primary);
|
const primaryKeys = table.fields.filter((f) => f.primary);
|
||||||
|
Reference in New Issue
Block a user