diff --git a/packages/server/src/sdk/app/backups/imports.ts b/packages/server/src/sdk/app/backups/imports.ts index 977dea5b63..1c08c8c3bf 100644 --- a/packages/server/src/sdk/app/backups/imports.ts +++ b/packages/server/src/sdk/app/backups/imports.ts @@ -5,6 +5,7 @@ import { Automation, AutomationTriggerStepId, RowAttachment, + FieldType, } from "@budibase/types" import { getAutomationParams } from "../../../db/utils" import { budibaseTempDir } from "../../../utilities/budibaseDir" @@ -58,10 +59,19 @@ export async function updateAttachmentColumns(prodAppId: string, db: Database) { updatedRows = updatedRows.concat( rows.map(row => { for (let column of columns) { - if (Array.isArray(row[column])) { + const columnType = table.schema[column].type + if ( + columnType === FieldType.ATTACHMENTS && + Array.isArray(row[column]) + ) { row[column] = row[column].map((attachment: RowAttachment) => rewriteAttachmentUrl(prodAppId, attachment) ) + } else if ( + columnType === FieldType.ATTACHMENT_SINGLE && + row[column] + ) { + row[column] = rewriteAttachmentUrl(prodAppId, row[column]) } } return row diff --git a/packages/server/src/sdk/app/rows/attachments.ts b/packages/server/src/sdk/app/rows/attachments.ts index 8fd2ccf795..ee816ea1fc 100644 --- a/packages/server/src/sdk/app/rows/attachments.ts +++ b/packages/server/src/sdk/app/rows/attachments.ts @@ -30,7 +30,10 @@ export async function getRowsWithAttachments(appId: string, table: Table) { const db = dbCore.getDB(appId) const attachmentCols: string[] = [] for (let [key, column] of Object.entries(table.schema)) { - if (column.type === FieldType.ATTACHMENTS) { + if ( + column.type === FieldType.ATTACHMENTS || + column.type === FieldType.ATTACHMENT_SINGLE + ) { attachmentCols.push(key) } } diff --git a/packages/server/src/sdk/tests/attachments.spec.ts b/packages/server/src/sdk/tests/attachments.spec.ts index 3ae9a33d8b..46165f68fc 100644 --- a/packages/server/src/sdk/tests/attachments.spec.ts +++ b/packages/server/src/sdk/tests/attachments.spec.ts @@ -31,9 +31,13 @@ describe("should be able to re-write attachment URLs", () => { sourceType: TableSourceType.INTERNAL, schema: { photo: { - type: FieldType.ATTACHMENTS, + type: FieldType.ATTACHMENT_SINGLE, name: "photo", }, + gallery: { + type: FieldType.ATTACHMENTS, + name: "gallery", + }, otherCol: { type: FieldType.STRING, name: "otherCol", @@ -43,7 +47,8 @@ describe("should be able to re-write attachment URLs", () => { for (let i = 0; i < FIND_LIMIT * 4; i++) { await config.api.row.save(table._id!, { - photo: [attachment], + photo: { ...attachment }, + gallery: [{ ...attachment }, { ...attachment }], otherCol: "string", }) } @@ -56,8 +61,12 @@ describe("should be able to re-write attachment URLs", () => { ) for (const row of rows) { expect(row.otherCol).toBe("string") - expect(row.photo[0].url).toBe("") - expect(row.photo[0].key).toBe(`${db.name}/attachments/a.png`) + expect(row.photo.url).toBe("") + expect(row.photo.key).toBe(`${db.name}/attachments/a.png`) + expect(row.gallery[0].url).toBe("") + expect(row.gallery[0].key).toBe(`${db.name}/attachments/a.png`) + expect(row.gallery[1].url).toBe("") + expect(row.gallery[1].key).toBe(`${db.name}/attachments/a.png`) } }) })