diff --git a/packages/server/src/sdk/app/applications/import.ts b/packages/server/src/sdk/app/applications/import.ts index aa88244492..a6bdf3d9d9 100644 --- a/packages/server/src/sdk/app/applications/import.ts +++ b/packages/server/src/sdk/app/applications/import.ts @@ -1,6 +1,6 @@ import { db as dbCore } from "@budibase/backend-core" import { - DocumentsToImport, + DocumentTypesToImport, Document, Database, RowValue, @@ -15,7 +15,7 @@ export type FileAttributes = { async function removeImportableDocuments(db: Database) { // get the references to the documents, not the whole document const docPromises = [] - for (let docType of DocumentsToImport) { + for (let docType of DocumentTypesToImport) { docPromises.push(db.allDocs(dbCore.getDocParams(docType))) } let documentRefs: { _id: string; _rev: string }[] = [] @@ -28,15 +28,13 @@ async function removeImportableDocuments(db: Database) { ) } // add deletion key - documentRefs = documentRefs.map(ref => ({ _deleted: true, ...ref })) - // perform deletion - await db.bulkDocs(documentRefs) + return documentRefs.map(ref => ({ _deleted: true, ...ref })) } async function getImportableDocuments(db: Database) { // get the whole document const docPromises = [] - for (let docType of DocumentsToImport) { + for (let docType of DocumentTypesToImport) { docPromises.push( db.allDocs(dbCore.getDocParams(docType, null, { include_docs: true })) ) @@ -78,9 +76,9 @@ export async function updateWithExport( // get the documents to copy const documents = await getImportableDocuments(tempDb) // clear out the old documents - await removeImportableDocuments(appDb) + const toDelete = await removeImportableDocuments(appDb) // now write the import documents - await appDb.bulkDocs(documents) + await appDb.bulkDocs([...toDelete, documents]) } finally { await tempDb.destroy() } diff --git a/packages/types/src/documents/document.ts b/packages/types/src/documents/document.ts index 65168810e7..763da62d61 100644 --- a/packages/types/src/documents/document.ts +++ b/packages/types/src/documents/document.ts @@ -42,7 +42,7 @@ export enum DocumentType { // these are the core documents that make up the data, design // and automation sections of an app. This excludes any internal // rows as we shouldn't import data. -export const DocumentsToImport: DocumentType[] = [ +export const DocumentTypesToImport: DocumentType[] = [ DocumentType.ROLE, DocumentType.DATASOURCE, DocumentType.DATASOURCE_PLUS,