Last PR comments.

This commit is contained in:
mike12345567 2023-09-25 17:00:20 +01:00
parent 4d1c749444
commit 3d143c28a9
2 changed files with 7 additions and 9 deletions

View File

@ -1,6 +1,6 @@
import { db as dbCore } from "@budibase/backend-core" import { db as dbCore } from "@budibase/backend-core"
import { import {
DocumentsToImport, DocumentTypesToImport,
Document, Document,
Database, Database,
RowValue, RowValue,
@ -15,7 +15,7 @@ export type FileAttributes = {
async function removeImportableDocuments(db: Database) { async function removeImportableDocuments(db: Database) {
// get the references to the documents, not the whole document // get the references to the documents, not the whole document
const docPromises = [] const docPromises = []
for (let docType of DocumentsToImport) { for (let docType of DocumentTypesToImport) {
docPromises.push(db.allDocs(dbCore.getDocParams(docType))) docPromises.push(db.allDocs(dbCore.getDocParams(docType)))
} }
let documentRefs: { _id: string; _rev: string }[] = [] let documentRefs: { _id: string; _rev: string }[] = []
@ -28,15 +28,13 @@ async function removeImportableDocuments(db: Database) {
) )
} }
// add deletion key // add deletion key
documentRefs = documentRefs.map(ref => ({ _deleted: true, ...ref })) return documentRefs.map(ref => ({ _deleted: true, ...ref }))
// perform deletion
await db.bulkDocs(documentRefs)
} }
async function getImportableDocuments(db: Database) { async function getImportableDocuments(db: Database) {
// get the whole document // get the whole document
const docPromises = [] const docPromises = []
for (let docType of DocumentsToImport) { for (let docType of DocumentTypesToImport) {
docPromises.push( docPromises.push(
db.allDocs(dbCore.getDocParams(docType, null, { include_docs: true })) db.allDocs(dbCore.getDocParams(docType, null, { include_docs: true }))
) )
@ -78,9 +76,9 @@ export async function updateWithExport(
// get the documents to copy // get the documents to copy
const documents = await getImportableDocuments(tempDb) const documents = await getImportableDocuments(tempDb)
// clear out the old documents // clear out the old documents
await removeImportableDocuments(appDb) const toDelete = await removeImportableDocuments(appDb)
// now write the import documents // now write the import documents
await appDb.bulkDocs(documents) await appDb.bulkDocs([...toDelete, documents])
} finally { } finally {
await tempDb.destroy() await tempDb.destroy()
} }

View File

@ -42,7 +42,7 @@ export enum DocumentType {
// these are the core documents that make up the data, design // these are the core documents that make up the data, design
// and automation sections of an app. This excludes any internal // and automation sections of an app. This excludes any internal
// rows as we shouldn't import data. // rows as we shouldn't import data.
export const DocumentsToImport: DocumentType[] = [ export const DocumentTypesToImport: DocumentType[] = [
DocumentType.ROLE, DocumentType.ROLE,
DocumentType.DATASOURCE, DocumentType.DATASOURCE,
DocumentType.DATASOURCE_PLUS, DocumentType.DATASOURCE_PLUS,