diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index f6a4f29a06..d3eaaa5d6a 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -34,7 +34,12 @@ import { getBindings } from "components/backend/DataTable/formula" import JSONSchemaModal from "./JSONSchemaModal.svelte" import { ValidColumnNameRegex } from "@budibase/shared-core" - import { FieldType, FieldSubtype, SourceName } from "@budibase/types" + import { + FieldType, + FieldSubtype, + SourceName, + FieldTypeSubtypes, + } from "@budibase/types" import RelationshipSelector from "components/common/RelationshipSelector.svelte" import { RowUtils } from "@budibase/frontend-core" import ServerBindingPanel from "components/common/bindings/ServerBindingPanel.svelte" @@ -191,8 +196,10 @@ // don't make field IDs for auto types if (type === AUTO_TYPE || autocolumn) { return type.toUpperCase() - } else { + } else if (type === FieldType.BB_REFERENCE) { return `${type}${subtype || ""}`.toUpperCase() + } else { + return type.toUpperCase() } } @@ -705,17 +712,12 @@ /> {:else if editableColumn.type === FieldType.ATTACHMENT} { if (!e.detail) { - editableColumn.constraints ??= { length: {} } - editableColumn.constraints.length ??= {} - editableColumn.constraints.length.maximum = 1 - editableColumn.constraints.length.message = - "cannot contain multiple files" + editableColumn.subtype = FieldTypeSubtypes.ATTACHMENT.SINGLE } else { - delete editableColumn.constraints?.length?.maximum - delete editableColumn.constraints?.length?.message + delete editableColumn.subtype } }} thin diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 9e1bb59e9d..ac13617869 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -30,6 +30,7 @@ import { View, RelationshipFieldMetadata, FieldType, + FieldTypeSubtypes, } from "@budibase/types" export async function clearColumns(table: Table, columnNames: string[]) { @@ -88,6 +89,24 @@ export async function checkForColumnUpdates( // Update views await checkForViewUpdates(updatedTable, deletedColumns, columnRename) } + + for (const attachmentColumn of Object.values(updatedTable.schema).filter( + column => + column.type === FieldType.ATTACHMENT && + column.subtype !== oldTable?.schema[column.name]?.subtype + )) { + if (attachmentColumn.subtype === FieldTypeSubtypes.ATTACHMENT.SINGLE) { + attachmentColumn.constraints ??= { length: {} } + attachmentColumn.constraints.length ??= {} + attachmentColumn.constraints.length.maximum = 1 + attachmentColumn.constraints.length.message = + "cannot contain multiple files" + } else { + delete attachmentColumn.constraints?.length?.maximum + delete attachmentColumn.constraints?.length?.message + } + } + return { rows: updatedRows, table: updatedTable } } diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 17abf747b2..0e5bec134c 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -119,6 +119,7 @@ export interface FieldConstraints { length?: { minimum?: string | number | null maximum?: string | number | null + message?: string } numericality?: { greaterThanOrEqualTo: string | null