Fill in datatypes for mysql

This commit is contained in:
1ilit 2024-06-15 20:37:39 +03:00
parent bff10e6fe9
commit 77d1a9ea41

View File

@ -6,8 +6,8 @@ const binaryRegex = /^[01]+$/;
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
export const defaultTypes = { export const defaultTypes = {
INT: { INTEGER: {
type: "INT", type: "INTEGER",
checkDefault: (field) => { checkDefault: (field) => {
return intRegex.test(field.default); return intRegex.test(field.default);
}, },
@ -263,49 +263,416 @@ export const defaultTypes = {
}; };
export const mysqlTypes = { export const mysqlTypes = {
TINYINT: { type: "TINYINT", checkDefault: (field) => {} }, TINYINT: {
SMALLINT: { type: "SMALLINT", checkDefault: (field) => {} }, type: "TINYINT",
MEDIUMINT: { type: "MEDIUMINT", checkDefault: (field) => {} }, checkDefault: (field) => {
INT: { type: "INT", checkDefault: (field) => {} }, return intRegex.test(field.default);
INTEGER: { type: "INTEGER", checkDefault: (field) => {} }, },
BIGINT: { type: "BIGINT", checkDefault: (field) => {} }, hasCheck: true,
DECIMAL: { type: "DECIMAL", checkDefault: (field) => {} }, isSized: false,
NUMERIC: { type: "NUMERIC", checkDefault: (field) => {} }, hasPrecision: false,
FLOAT: { type: "FLOAT", checkDefault: (field) => {} }, canIncrement: true,
DOUBLE: { type: "DOUBLE", checkDefault: (field) => {} }, },
BIT: { type: "BIT", checkDefault: (field) => {} }, SMALLINT: {
BOOLEAN: { type: "BOOLEAN", checkDefault: (field) => {} }, type: "SMALLINT",
DATE: { type: "DATE", checkDefault: (field) => {} }, checkDefault: (field) => {
DATETIME: { type: "DATETIME", checkDefault: (field) => {} }, return intRegex.test(field.default);
TIMESTAMP: { type: "TIMESTAMP", checkDefault: (field) => {} }, },
TIME: { type: "TIME", checkDefault: (field) => {} }, hasCheck: true,
YEAR: { type: "YEAR", checkDefault: (field) => {} }, isSized: false,
CHAR: { type: "CHAR", checkDefault: (field) => {} }, hasPrecision: false,
VARCHAR: { type: "VARCHAR", checkDefault: (field) => {} }, canIncrement: true,
BINARY: { type: "BINARY", checkDefault: (field) => {} }, },
VARBINARY: { type: "VARBINARY", checkDefault: (field) => {} }, MEDIUMINT: {
TINYBLOB: { type: "TINYBLOB", checkDefault: (field) => {} }, type: "MEDIUMINT",
BLOB: { type: "BLOB", checkDefault: (field) => {} }, checkDefault: (field) => {
MEDIUMBLOB: { type: "MEDIUMBLOB", checkDefault: (field) => {} }, return intRegex.test(field.default);
LONGBLOB: { type: "LONGBLOB", checkDefault: (field) => {} }, },
TINYTEXT: { type: "TINYTEXT", checkDefault: (field) => {} }, hasCheck: true,
TEXT: { type: "TEXT", checkDefault: (field) => {} }, isSized: false,
MEDIUMTEXT: { type: "MEDIUMTEXT", checkDefault: (field) => {} }, hasPrecision: false,
LONGTEXT: { type: "LONGTEXT", checkDefault: (field) => {} }, canIncrement: true,
ENUM: { type: "ENUM", checkDefault: (field) => {} }, },
SET: { type: "SET", checkDefault: (field) => {} }, INTEGER: {
GEOMETRY: { type: "GEOMETRY", checkDefault: (field) => {} }, type: "INTEGER",
POINT: { type: "POINT", checkDefault: (field) => {} }, checkDefault: (field) => {
LINESTRING: { type: "LINESTRING", checkDefault: (field) => {} }, return intRegex.test(field.default);
POLYGON: { type: "POLYGON", checkDefault: (field) => {} }, },
MULTIPOINT: { type: "MULTIPOINT", checkDefault: (field) => {} }, hasCheck: true,
MULTILINESTRING: { type: "MULTILINESTRING", checkDefault: (field) => {} }, isSized: false,
MULTIPOLYGON: { type: "MULTIPOLYGON", checkDefault: (field) => {} }, hasPrecision: false,
canIncrement: true,
},
BIGINT: {
type: "BIGINT",
checkDefault: (field) => {
return intRegex.test(field.default);
},
hasCheck: true,
isSized: false,
hasPrecision: false,
canIncrement: true,
},
DECIMAL: {
type: "DECIMAL",
checkDefault: (field) => {
return doubleRegex.test(field.default);
},
hasCheck: true,
isSized: false,
hasPrecision: true,
},
NUMERIC: {
type: "NUMERIC",
checkDefault: (field) => {
return doubleRegex.test(field.default);
},
hasCheck: true,
isSized: false,
hasPrecision: true,
},
FLOAT: {
type: "FLOAT",
checkDefault: (field) => {
return doubleRegex.test(field.default);
},
hasCheck: true,
isSized: false,
hasPrecision: true,
},
DOUBLE: {
type: "DOUBLE",
checkDefault: (field) => {
return doubleRegex.test(field.default);
},
hasCheck: true,
isSized: false,
hasPrecision: true,
},
BIT: {
type: "BIT",
checkDefault: (field) => {
return field.default === "1" || field.default === "0";
},
hasCheck: true,
isSized: false,
hasPrecision: true,
},
BOOLEAN: {
type: "BOOLEAN",
checkDefault: (field) => {
return (
field.default.trim().toLowerCase() === "false" ||
field.default.trim().toLowerCase() === "true"
);
},
hasCheck: false,
isSized: false,
hasPrecision: false,
},
TIME: {
type: "TIME",
checkDefault: (field) => {
return /^(?:[01]?\d|2[0-3]):[0-5]?\d:[0-5]?\d$/.test(field.default);
},
hasCheck: false,
isSized: false,
hasPrecision: false,
hasQuotes: true,
},
TIMESTAMP: {
type: "TIMESTAMP",
checkDefault: (field) => {
if (field.default.toUpperCase() === "CURRENT_TIMESTAMP") {
return true;
}
if (!/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(field.default)) {
return false;
}
const content = field.default.split(" ");
const date = content[0].split("-");
return parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038;
},
hasCheck: false,
isSized: false,
hasPrecision: false,
hasQuotes: true,
},
DATE: {
type: "DATE",
checkDefault: (field) => {
return /^\d{4}-\d{2}-\d{2}$/.test(field.default);
},
hasCheck: false,
isSized: false,
hasPrecision: false,
hasQuotes: true,
},
DATETIME: {
type: "DATETIME",
checkDefault: (field) => {
if (field.default.toUpperCase() === "CURRENT_TIMESTAMP") {
return true;
}
if (!/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(field.default)) {
return false;
}
const c = field.default.split(" ");
const d = c[0].split("-");
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
},
hasCheck: false,
isSized: false,
hasPrecision: false,
hasQuotes: true,
},
YEAR: {
type: "YEAR",
checkDefault: (field) => {
return /^\d{4}$/.test(field.default);
},
hasCheck: false,
isSized: false,
hasPrecision: false,
},
CHAR: {
type: "CHAR",
checkDefault: (field) => {
if (strHasQuotes(field.default)) {
return field.default.length - 2 <= field.size;
}
return field.default.length <= field.size;
},
hasCheck: true,
isSized: true,
hasPrecision: false,
defaultSize: 1,
hasQuotes: true,
},
VARCHAR: {
type: "VARCHAR",
checkDefault: (field) => {
if (strHasQuotes(field.default)) {
return field.default.length - 2 <= field.size;
}
return field.default.length <= field.size;
},
hasCheck: true,
isSized: true,
hasPrecision: false,
defaultSize: 255,
hasQuotes: true,
},
BINARY: {
type: "BINARY",
checkDefault: (field) => {
return (
field.default.length <= field.size && binaryRegex.test(field.default)
);
},
hasCheck: false,
isSized: true,
hasPrecision: false,
defaultSize: 1,
hasQuotes: true,
},
VARBINARY: {
type: "VARBINARY",
checkDefault: (field) => {
return (
field.default.length <= field.size && binaryRegex.test(field.default)
);
},
hasCheck: false,
isSized: true,
hasPrecision: false,
defaultSize: 255,
hasQuotes: true,
},
TINYBLOB: {
type: "TINYBLOB",
checkDefault: (field) => false,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
},
BLOB: {
type: "BLOB",
checkDefault: (field) => false,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
},
MEDIUMBLOB: {
type: "MEDIUMBLOB",
checkDefault: (field) => false,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
},
LONGBLOB: {
type: "LONGBLOB",
checkDefault: (field) => false,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
},
TINYTEXT: {
type: "TINYTEXT",
checkDefault: (field) => {
if (strHasQuotes(field.default)) {
return field.default.length - 2 <= field.size;
}
return field.default.length <= field.size;
},
hasCheck: true,
isSized: true,
hasPrecision: false,
defaultSize: 65535,
hasQuotes: true,
},
TEXT: {
type: "TEXT",
checkDefault: (field) => {
if (strHasQuotes(field.default)) {
return field.default.length - 2 <= field.size;
}
return field.default.length <= field.size;
},
hasCheck: true,
isSized: true,
hasPrecision: false,
defaultSize: 65535,
hasQuotes: true,
},
MEDIUMTEXT: {
type: "MEDIUMTEXT",
checkDefault: (field) => {
if (strHasQuotes(field.default)) {
return field.default.length - 2 <= field.size;
}
return field.default.length <= field.size;
},
hasCheck: true,
isSized: true,
hasPrecision: false,
defaultSize: 65535,
hasQuotes: true,
},
LONGTEXT: {
type: "LONGTEXT",
checkDefault: (field) => {
if (strHasQuotes(field.default)) {
return field.default.length - 2 <= field.size;
}
return field.default.length <= field.size;
},
hasCheck: true,
isSized: true,
hasPrecision: false,
defaultSize: 65535,
hasQuotes: true,
},
ENUM: {
type: "ENUM",
checkDefault: (field) => {
return field.values.includes(field.default);
},
hasCheck: false,
isSized: false,
hasPrecision: false,
hasQuotes: true,
},
SET: {
type: "SET",
checkDefault: (field) => {
const defaultValues = field.default.split(",");
for (let i = 0; i < defaultValues.length; i++) {
if (!field.values.includes(defaultValues[i].trim())) return false;
}
return true;
},
hasCheck: false,
isSized: false,
hasPrecision: false,
noDefault: true,
},
GEOMETRY: {
type: "GEOMETRY",
checkDefault: (field) => false,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
},
POINT: {
type: "POINT",
checkDefault: (field) => false,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
},
LINESTRING: {
type: "LINESTRING",
checkDefault: (field) => false,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
},
POLYGON: {
type: "POLYGON",
checkDefault: (field) => false,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
},
MULTIPOINT: {
type: "MULTIPOINT",
checkDefault: (field) => false,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
},
MULTILINESTRING: {
type: "MULTILINESTRING",
checkDefault: (field) => false,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
},
MULTIPOLYGON: {
type: "MULTIPOLYGON",
checkDefault: (field) => false,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
},
GEOMETRYCOLLECTION: { GEOMETRYCOLLECTION: {
type: "GEOMETRYCOLLECTION", type: "GEOMETRYCOLLECTION",
checkDefault: (field) => {}, checkDefault: (field) => false,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
},
JSON: {
type: "JSON",
checkDefault: (field) => false,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
}, },
JSON: { type: "JSON", checkDefault: (field) => {} },
}; };
export const postgresTypes = { export const postgresTypes = {
@ -431,7 +798,6 @@ export const sqliteTypes = {
hasPrecision: false, hasPrecision: false,
noDefault: true, noDefault: true,
}, },
TIME: { TIME: {
type: "TIME", type: "TIME",
checkDefault: (field) => { checkDefault: (field) => {