Add constraints and extra fields

This commit is contained in:
Adria Navarro 2024-04-19 12:40:39 +02:00
parent 72c65cd7fd
commit 16d2c06b8a
3 changed files with 12 additions and 2 deletions

View File

@ -281,6 +281,9 @@ describe("/datasources", () => {
[FieldType.STRING]: { [FieldType.STRING]: {
name: "string", name: "string",
type: FieldType.STRING, type: FieldType.STRING,
constraints: {
presence: true,
},
}, },
[FieldType.LONGFORM]: { [FieldType.LONGFORM]: {
name: "longform", name: "longform",
@ -289,6 +292,9 @@ describe("/datasources", () => {
[FieldType.OPTIONS]: { [FieldType.OPTIONS]: {
name: "options", name: "options",
type: FieldType.OPTIONS, type: FieldType.OPTIONS,
constraints: {
presence: { allowEmpty: false },
},
}, },
[FieldType.NUMBER]: { [FieldType.NUMBER]: {
name: "number", name: "number",
@ -305,6 +311,8 @@ describe("/datasources", () => {
[FieldType.DATETIME]: { [FieldType.DATETIME]: {
name: "datetime", name: "datetime",
type: FieldType.DATETIME, type: FieldType.DATETIME,
dateOnly: true,
timeOnly: false,
}, },
[FieldType.LINK]: { [FieldType.LINK]: {
name: "link", name: "link",

View File

@ -4,6 +4,7 @@ import {
Datasource, Datasource,
FieldType, FieldType,
TableSourceType, TableSourceType,
FieldSchema,
} from "@budibase/types" } from "@budibase/types"
import { DocumentType, SEPARATOR } from "../../db/utils" import { DocumentType, SEPARATOR } from "../../db/utils"
import { InvalidColumns, DEFAULT_BB_DATASOURCE_ID } from "../../constants" import { InvalidColumns, DEFAULT_BB_DATASOURCE_ID } from "../../constants"
@ -260,14 +261,14 @@ export function generateColumnDefinition(config: {
constraints.inclusion = options constraints.inclusion = options
} }
const schema: any = { const schema: FieldSchema = {
type: foundType, type: foundType,
externalType, externalType,
autocolumn, autocolumn,
name, name,
constraints, constraints,
} }
if (foundType === FieldType.DATETIME) { if (schema.type === FieldType.DATETIME) {
schema.dateOnly = SQL_DATE_ONLY_TYPES.includes(lowerCaseType) schema.dateOnly = SQL_DATE_ONLY_TYPES.includes(lowerCaseType)
schema.timeOnly = SQL_TIME_ONLY_TYPES.includes(lowerCaseType) schema.timeOnly = SQL_TIME_ONLY_TYPES.includes(lowerCaseType)
} }

View File

@ -91,6 +91,7 @@ export interface DateFieldMetadata extends Omit<BaseFieldSchema, "subtype"> {
type: FieldType.DATETIME type: FieldType.DATETIME
ignoreTimezones?: boolean ignoreTimezones?: boolean
timeOnly?: boolean timeOnly?: boolean
dateOnly?: boolean
subtype?: AutoFieldSubType.CREATED_AT | AutoFieldSubType.UPDATED_AT subtype?: AutoFieldSubType.CREATED_AT | AutoFieldSubType.UPDATED_AT
} }