From 33656a4ae5756fc6894a031dc27ec544618ef9f4 Mon Sep 17 00:00:00 2001 From: andz-bb Date: Fri, 8 Nov 2024 14:04:51 +0000 Subject: [PATCH 1/2] prevent attachment column updates when importing budibase templates --- packages/server/src/api/controllers/application.ts | 6 +++++- packages/server/src/sdk/app/backups/imports.ts | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/application.ts b/packages/server/src/api/controllers/application.ts index e7d0ed7ba74..101257c3216 100644 --- a/packages/server/src/api/controllers/application.ts +++ b/packages/server/src/api/controllers/application.ts @@ -153,7 +153,11 @@ async function createInstance(appId: string, template: AppTemplate) { await createAllSearchIndex() if (template && template.useTemplate) { - await sdk.backups.importApp(appId, db, template) + const opts = { + importObjStoreContents: true, + updateAttachmentColumns: !template.key, // preserve attachments when using Budibase templates + } + await sdk.backups.importApp(appId, db, template, opts) } else { // create the users table await db.put(USERS_TABLE_SCHEMA) diff --git a/packages/server/src/sdk/app/backups/imports.ts b/packages/server/src/sdk/app/backups/imports.ts index f69fb9f5c86..edc8d9ea6fd 100644 --- a/packages/server/src/sdk/app/backups/imports.ts +++ b/packages/server/src/sdk/app/backups/imports.ts @@ -170,7 +170,10 @@ export async function importApp( appId: string, db: Database, template: TemplateType, - opts: { importObjStoreContents: boolean } = { importObjStoreContents: true } + opts: { + importObjStoreContents: boolean + updateAttachmentColumns?: boolean + } = { importObjStoreContents: true, updateAttachmentColumns: true } ) { let prodAppId = dbCore.getProdAppID(appId) let dbStream: any @@ -219,7 +222,9 @@ export async function importApp( if (!ok) { throw "Error loading database dump from template." } - await updateAttachmentColumns(prodAppId, db) + if (opts.updateAttachmentColumns) { + await updateAttachmentColumns(prodAppId, db) + } await updateAutomations(prodAppId, db) // clear up afterward if (tmpPath) { From 932b119a66c246aad0746fc986d2d12524183148 Mon Sep 17 00:00:00 2001 From: andz-bb Date: Fri, 8 Nov 2024 14:24:31 +0000 Subject: [PATCH 2/2] make opt not optional --- packages/server/src/sdk/app/applications/import.ts | 1 + packages/server/src/sdk/app/backups/imports.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/server/src/sdk/app/applications/import.ts b/packages/server/src/sdk/app/applications/import.ts index f712548fcbb..c63708f42e8 100644 --- a/packages/server/src/sdk/app/applications/import.ts +++ b/packages/server/src/sdk/app/applications/import.ts @@ -123,6 +123,7 @@ export async function updateWithExport( // don't need obj store, the existing app already has everything we need await backups.importApp(devId, tempDb, template, { importObjStoreContents: false, + updateAttachmentColumns: true, }) const newMetadata = await getNewAppMetadata(tempDb, appDb) // get the documents to copy diff --git a/packages/server/src/sdk/app/backups/imports.ts b/packages/server/src/sdk/app/backups/imports.ts index edc8d9ea6fd..3ec0e8833b1 100644 --- a/packages/server/src/sdk/app/backups/imports.ts +++ b/packages/server/src/sdk/app/backups/imports.ts @@ -172,7 +172,7 @@ export async function importApp( template: TemplateType, opts: { importObjStoreContents: boolean - updateAttachmentColumns?: boolean + updateAttachmentColumns: boolean } = { importObjStoreContents: true, updateAttachmentColumns: true } ) { let prodAppId = dbCore.getProdAppID(appId)