From 1d041a3dd5c857817e065f5e3f8e41d372694f2b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 2 May 2023 12:48:05 +0100 Subject: [PATCH] Support nulls when optional --- packages/server/src/utilities/schema.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/server/src/utilities/schema.ts b/packages/server/src/utilities/schema.ts index f3d98d35c9..7b5de7898a 100644 --- a/packages/server/src/utilities/schema.ts +++ b/packages/server/src/utilities/schema.ts @@ -4,6 +4,9 @@ interface SchemaColumn { readonly name: string readonly type: FieldTypes readonly autocolumn?: boolean + readonly constraints?: { + presence: boolean + } } interface Schema { @@ -76,6 +79,11 @@ export function validate(rows: Rows, schema: Schema): ValidationResults { // If the columnType is not a string, then it's not present in the schema, and should be added to the invalid columns array if (typeof columnType !== "string") { results.invalidColumns.push(columnName) + } else if ( + columnData == null && + !schema[columnName].constraints?.presence + ) { + results.schemaValidation[columnName] = true } else if ( // If there's no data for this field don't bother with further checks // If the field is already marked as invalid there's no need for further checks