Support special values for postgres defaults (#238)
This commit is contained in:
parent
557ce72961
commit
419ea13c4b
@ -876,7 +876,19 @@ const postgresTypesBase = {
|
|||||||
DATE: {
|
DATE: {
|
||||||
type: "DATE",
|
type: "DATE",
|
||||||
checkDefault: (field) => {
|
checkDefault: (field) => {
|
||||||
return /^\d{4}-\d{2}-\d{2}$/.test(field.default);
|
const specialValues = [
|
||||||
|
"epoch",
|
||||||
|
"infinity",
|
||||||
|
"-infinity",
|
||||||
|
"now",
|
||||||
|
"today",
|
||||||
|
"tomorrow",
|
||||||
|
"yesterday",
|
||||||
|
];
|
||||||
|
return (
|
||||||
|
/^\d{4}-\d{2}-\d{2}$/.test(field.default) ||
|
||||||
|
specialValues.includes(field.default.toLowerCase())
|
||||||
|
);
|
||||||
},
|
},
|
||||||
hasCheck: false,
|
hasCheck: false,
|
||||||
isSized: false,
|
isSized: false,
|
||||||
@ -886,7 +898,11 @@ const postgresTypesBase = {
|
|||||||
TIME: {
|
TIME: {
|
||||||
type: "TIME",
|
type: "TIME",
|
||||||
checkDefault: (field) => {
|
checkDefault: (field) => {
|
||||||
return /^(?:[01]?\d|2[0-3]):[0-5]?\d:[0-5]?\d$/.test(field.default);
|
const specialValues = ["now", "allballs"];
|
||||||
|
return (
|
||||||
|
/^(?:[01]?\d|2[0-3]):[0-5]?\d:[0-5]?\d$/.test(field.default) ||
|
||||||
|
specialValues.includes(field.default.toLowerCase())
|
||||||
|
);
|
||||||
},
|
},
|
||||||
hasCheck: false,
|
hasCheck: false,
|
||||||
isSized: false,
|
isSized: false,
|
||||||
@ -896,15 +912,23 @@ const postgresTypesBase = {
|
|||||||
TIMESTAMP: {
|
TIMESTAMP: {
|
||||||
type: "TIMESTAMP",
|
type: "TIMESTAMP",
|
||||||
checkDefault: (field) => {
|
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 content = field.default.split(" ");
|
||||||
const date = content[0].split("-");
|
const date = content[0].split("-");
|
||||||
return parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038;
|
const specialValues = [
|
||||||
|
"epoch",
|
||||||
|
"infinity",
|
||||||
|
"-infinity",
|
||||||
|
"now",
|
||||||
|
"today",
|
||||||
|
"tomorrow",
|
||||||
|
"yesterday",
|
||||||
|
"current_timestamp",
|
||||||
|
];
|
||||||
|
return (
|
||||||
|
/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(field.default) ||
|
||||||
|
(parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038) ||
|
||||||
|
specialValues.includes(field.default.toLowerCase())
|
||||||
|
);
|
||||||
},
|
},
|
||||||
hasCheck: false,
|
hasCheck: false,
|
||||||
isSized: false,
|
isSized: false,
|
||||||
@ -914,11 +938,20 @@ const postgresTypesBase = {
|
|||||||
TIMESTAMPTZ: {
|
TIMESTAMPTZ: {
|
||||||
type: "TIMESTAMPTZ",
|
type: "TIMESTAMPTZ",
|
||||||
checkDefault: (field) => {
|
checkDefault: (field) => {
|
||||||
if (field.default.toUpperCase() === "CURRENT_TIMESTAMP") {
|
const specialValues = [
|
||||||
return true;
|
"epoch",
|
||||||
}
|
"infinity",
|
||||||
return /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([+-]\d{2}:\d{2})?$/.test(
|
"-infinity",
|
||||||
field.default,
|
"now",
|
||||||
|
"today",
|
||||||
|
"tomorrow",
|
||||||
|
"yesterday",
|
||||||
|
"current_timestamp",
|
||||||
|
];
|
||||||
|
return (
|
||||||
|
/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([+-]\d{2}:\d{2})?$/.test(
|
||||||
|
field.default,
|
||||||
|
) || specialValues.includes(field.default.toLowerCase())
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
hasCheck: false,
|
hasCheck: false,
|
||||||
|
Loading…
Reference in New Issue
Block a user