mirror of
https://github.com/directus/directus.git
synced 2026-02-07 05:55:06 -05:00
Added correct null parsing to Directus schemas (#13873)
* Added correct null parsing to Directus schemas * Bump knex-schema-inspector To make sure we don't upset MariaDB folks Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
@@ -588,11 +588,6 @@ export class FieldsService {
|
||||
) {
|
||||
const precision = field.schema.default_value.match(REGEX_BETWEEN_PARENS)![1];
|
||||
column.defaultTo(this.knex.fn.now(Number(precision)));
|
||||
} else if (
|
||||
typeof field.schema.default_value === 'string' &&
|
||||
['"null"', 'null'].includes(field.schema.default_value.toLowerCase())
|
||||
) {
|
||||
column.defaultTo(null);
|
||||
} else {
|
||||
column.defaultTo(field.schema.default_value);
|
||||
}
|
||||
|
||||
@@ -10,20 +10,8 @@ export default function getDefaultValue(
|
||||
): string | boolean | number | Record<string, any> | any[] | null {
|
||||
const type = getLocalType(column);
|
||||
|
||||
let defaultValue = column.default_value ?? null;
|
||||
const defaultValue = column.default_value ?? null;
|
||||
if (defaultValue === null) return null;
|
||||
if (defaultValue === 'null') return null;
|
||||
if (defaultValue === 'NULL') return null;
|
||||
|
||||
// Check if the default is wrapped in an extra pair of quotes, this happens in SQLite / MariaDB
|
||||
if (
|
||||
typeof defaultValue === 'string' &&
|
||||
((defaultValue.startsWith(`'`) && defaultValue.endsWith(`'`)) ||
|
||||
(defaultValue.startsWith(`"`) && defaultValue.endsWith(`"`)))
|
||||
) {
|
||||
defaultValue = defaultValue.slice(1, -1);
|
||||
}
|
||||
|
||||
if (defaultValue === '0000-00-00 00:00:00') return null;
|
||||
|
||||
switch (type) {
|
||||
|
||||
Reference in New Issue
Block a user