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:
Aiden Foxx
2022-06-13 20:59:47 +02:00
committed by GitHub
parent e54af6b1dd
commit e2cedccea9
8 changed files with 267 additions and 466 deletions

View File

@@ -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);
}

View File

@@ -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) {