From 16d2c06b8a33144a3364a581b86133a2a9feecc6 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 19 Apr 2024 12:40:39 +0200 Subject: [PATCH] Add constraints and extra fields --- packages/server/src/api/routes/tests/datasource.spec.ts | 8 ++++++++ packages/server/src/integrations/utils/utils.ts | 5 +++-- packages/types/src/documents/app/table/schema.ts | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/routes/tests/datasource.spec.ts b/packages/server/src/api/routes/tests/datasource.spec.ts index 0bdbbee27a..ec438611d4 100644 --- a/packages/server/src/api/routes/tests/datasource.spec.ts +++ b/packages/server/src/api/routes/tests/datasource.spec.ts @@ -281,6 +281,9 @@ describe("/datasources", () => { [FieldType.STRING]: { name: "string", type: FieldType.STRING, + constraints: { + presence: true, + }, }, [FieldType.LONGFORM]: { name: "longform", @@ -289,6 +292,9 @@ describe("/datasources", () => { [FieldType.OPTIONS]: { name: "options", type: FieldType.OPTIONS, + constraints: { + presence: { allowEmpty: false }, + }, }, [FieldType.NUMBER]: { name: "number", @@ -305,6 +311,8 @@ describe("/datasources", () => { [FieldType.DATETIME]: { name: "datetime", type: FieldType.DATETIME, + dateOnly: true, + timeOnly: false, }, [FieldType.LINK]: { name: "link", diff --git a/packages/server/src/integrations/utils/utils.ts b/packages/server/src/integrations/utils/utils.ts index 8d919159d8..e6d5bb872f 100644 --- a/packages/server/src/integrations/utils/utils.ts +++ b/packages/server/src/integrations/utils/utils.ts @@ -4,6 +4,7 @@ import { Datasource, FieldType, TableSourceType, + FieldSchema, } from "@budibase/types" import { DocumentType, SEPARATOR } from "../../db/utils" import { InvalidColumns, DEFAULT_BB_DATASOURCE_ID } from "../../constants" @@ -260,14 +261,14 @@ export function generateColumnDefinition(config: { constraints.inclusion = options } - const schema: any = { + const schema: FieldSchema = { type: foundType, externalType, autocolumn, name, constraints, } - if (foundType === FieldType.DATETIME) { + if (schema.type === FieldType.DATETIME) { schema.dateOnly = SQL_DATE_ONLY_TYPES.includes(lowerCaseType) schema.timeOnly = SQL_TIME_ONLY_TYPES.includes(lowerCaseType) } diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 86c34b6a5c..63a5876bc0 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -91,6 +91,7 @@ export interface DateFieldMetadata extends Omit { type: FieldType.DATETIME ignoreTimezones?: boolean timeOnly?: boolean + dateOnly?: boolean subtype?: AutoFieldSubType.CREATED_AT | AutoFieldSubType.UPDATED_AT }