1
0
Fork 0
mirror of synced 2024-07-07 15:25:52 +12:00

Merge pull request #10432 from Budibase/fix/export-no-auto-logs

Remove automation logs from app exports
This commit is contained in:
Michael Drury 2023-04-27 17:09:12 +01:00 committed by GitHub
commit 8acf2c4d18
3 changed files with 24 additions and 12 deletions

View file

@ -27,6 +27,7 @@ export const isProdAppID = dbCore.isProdAppID
export const USER_METDATA_PREFIX = `${DocumentType.ROW}${SEPARATOR}${dbCore.InternalTable.USER_METADATA}${SEPARATOR}`
export const LINK_USER_METADATA_PREFIX = `${DocumentType.LINK}${SEPARATOR}${dbCore.InternalTable.USER_METADATA}${SEPARATOR}`
export const TABLE_ROW_PREFIX = `${DocumentType.ROW}${SEPARATOR}${DocumentType.TABLE}`
export const AUTOMATION_LOG_PREFIX = `${DocumentType.AUTOMATION_LOG}${SEPARATOR}`
export const ViewName = dbCore.ViewName
export const InternalTables = dbCore.InternalTable
export const UNICODE_MAX = dbCore.UNICODE_MAX

View file

@ -3,6 +3,7 @@ import { budibaseTempDir } from "../../../utilities/budibaseDir"
import { streamFile, createTempFolder } from "../../../utilities/fileSystem"
import { ObjectStoreBuckets } from "../../../constants"
import {
AUTOMATION_LOG_PREFIX,
LINK_USER_METADATA_PREFIX,
TABLE_ROW_PREFIX,
USER_METDATA_PREFIX,
@ -20,11 +21,15 @@ const uuid = require("uuid/v4")
const tar = require("tar")
const MemoryStream = require("memorystream")
type ExportOpts = {
interface DBDumpOpts {
filter?: any
exportPath?: string
}
interface ExportOpts extends DBDumpOpts {
tar?: boolean
excludeRows?: boolean
excludeLogs?: boolean
}
function tarFilesToTmp(tmpDir: string, files: string[]) {
@ -49,7 +54,7 @@ function tarFilesToTmp(tmpDir: string, files: string[]) {
* a filter function or the name of the export.
* @return {*} either a readable stream or a string
*/
export async function exportDB(dbName: string, opts: ExportOpts = {}) {
export async function exportDB(dbName: string, opts: DBDumpOpts = {}) {
const exportOpts = {
filter: opts?.filter,
batch_size: 1000,
@ -76,11 +81,14 @@ export async function exportDB(dbName: string, opts: ExportOpts = {}) {
})
}
function defineFilter(excludeRows?: boolean) {
function defineFilter(excludeRows?: boolean, excludeLogs?: boolean) {
const ids = [USER_METDATA_PREFIX, LINK_USER_METADATA_PREFIX]
if (excludeRows) {
ids.push(TABLE_ROW_PREFIX)
}
if (excludeLogs) {
ids.push(AUTOMATION_LOG_PREFIX)
}
return (doc: any) =>
!ids.map(key => doc._id.includes(key)).reduce((prev, curr) => prev || curr)
}
@ -130,8 +138,7 @@ export async function exportApp(appId: string, config?: ExportOpts) {
// enforce an export of app DB to the tmp path
const dbPath = join(tmpPath, DB_EXPORT_FILE)
await exportDB(appId, {
...config,
filter: defineFilter(config?.excludeRows),
filter: defineFilter(config?.excludeRows, config?.excludeLogs),
exportPath: dbPath,
})
// if tar requested, return where the tarball is
@ -155,6 +162,10 @@ export async function exportApp(appId: string, config?: ExportOpts) {
* @returns {*} a readable stream of the backup which is written in real time
*/
export async function streamExportApp(appId: string, excludeRows: boolean) {
const tmpPath = await exportApp(appId, { excludeRows, tar: true })
const tmpPath = await exportApp(appId, {
excludeRows,
excludeLogs: true,
tar: true,
})
return streamFile(tmpPath)
}

View file

@ -1486,15 +1486,15 @@
pouchdb-promise "^6.0.4"
through2 "^2.0.0"
"@budibase/pro@2.5.6-alpha.37":
version "2.5.6-alpha.37"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.5.6-alpha.37.tgz#3f4c7ba36bd01e2f7cbc56461c1249cc4098bc38"
integrity sha512-D0P4ePioE43yZ+CvLE5XdO84x6/UcF8oY3rHIhd8+bS1LW1yrzAf4kG9lyBRsNUPZoTMPmJeD9zqGRw67pdjzA==
"@budibase/pro@2.5.6-alpha.38":
version "2.5.6-alpha.38"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.5.6-alpha.38.tgz#09e8dfbb6cefe856b5c01845a5a5c02a406faedf"
integrity sha512-CBZv6V+163USHPN0SuEIrXeGA+9gB1QNmHrMEPSmwlOCZbNW2dhniz00EVSuVh3ypHSjDECgozasDJTNRhiufQ==
dependencies:
"@budibase/backend-core" "2.5.6-alpha.37"
"@budibase/backend-core" "2.5.6-alpha.38"
"@budibase/shared-core" "2.4.44-alpha.1"
"@budibase/string-templates" "2.4.44-alpha.1"
"@budibase/types" "2.5.6-alpha.37"
"@budibase/types" "2.5.6-alpha.38"
"@koa/router" "8.0.8"
bull "4.10.1"
joi "17.6.0"