Merge pull request #9849 from Budibase/fix/9739
Fix for exporting/importing apps with different attachment columns
This commit is contained in:
commit
3e3db5c712
|
@ -87,6 +87,7 @@ export const runMigration = async (
|
||||||
const lengthStatement = length > 1 ? `[${count}/${length}]` : ""
|
const lengthStatement = length > 1 ? `[${count}/${length}]` : ""
|
||||||
|
|
||||||
const db = getDB(dbName)
|
const db = getDB(dbName)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const doc = await getMigrationsDoc(db)
|
const doc = await getMigrationsDoc(db)
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
export const DB_EXPORT_FILE = "db.txt"
|
export const DB_EXPORT_FILE = "db.txt"
|
||||||
export const GLOBAL_DB_EXPORT_FILE = "global.txt"
|
export const GLOBAL_DB_EXPORT_FILE = "global.txt"
|
||||||
|
export const STATIC_APP_FILES = ["manifest.json", "budibase-client.js"]
|
||||||
|
|
|
@ -7,10 +7,15 @@ import {
|
||||||
TABLE_ROW_PREFIX,
|
TABLE_ROW_PREFIX,
|
||||||
USER_METDATA_PREFIX,
|
USER_METDATA_PREFIX,
|
||||||
} from "../../../db/utils"
|
} from "../../../db/utils"
|
||||||
import { DB_EXPORT_FILE, GLOBAL_DB_EXPORT_FILE } from "./constants"
|
import {
|
||||||
|
DB_EXPORT_FILE,
|
||||||
|
GLOBAL_DB_EXPORT_FILE,
|
||||||
|
STATIC_APP_FILES,
|
||||||
|
} from "./constants"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import env from "../../../environment"
|
import env from "../../../environment"
|
||||||
|
|
||||||
const uuid = require("uuid/v4")
|
const uuid = require("uuid/v4")
|
||||||
const tar = require("tar")
|
const tar = require("tar")
|
||||||
const MemoryStream = require("memorystream")
|
const MemoryStream = require("memorystream")
|
||||||
|
@ -91,14 +96,25 @@ export async function exportApp(appId: string, config?: ExportOpts) {
|
||||||
const prodAppId = dbCore.getProdAppID(appId)
|
const prodAppId = dbCore.getProdAppID(appId)
|
||||||
const appPath = `${prodAppId}/`
|
const appPath = `${prodAppId}/`
|
||||||
// export bucket contents
|
// export bucket contents
|
||||||
let tmpPath
|
let tmpPath = createTempFolder(uuid())
|
||||||
if (!env.isTest()) {
|
if (!env.isTest()) {
|
||||||
tmpPath = await objectStore.retrieveDirectory(
|
// write just the static files
|
||||||
ObjectStoreBuckets.APPS,
|
if (config?.excludeRows) {
|
||||||
appPath
|
for (let path of STATIC_APP_FILES) {
|
||||||
)
|
const contents = await objectStore.retrieve(
|
||||||
} else {
|
ObjectStoreBuckets.APPS,
|
||||||
tmpPath = createTempFolder(uuid())
|
join(appPath, path)
|
||||||
|
)
|
||||||
|
fs.writeFileSync(join(tmpPath, path), contents)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// get all of the files
|
||||||
|
else {
|
||||||
|
tmpPath = await objectStore.retrieveDirectory(
|
||||||
|
ObjectStoreBuckets.APPS,
|
||||||
|
appPath
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const downloadedPath = join(tmpPath, appPath)
|
const downloadedPath = join(tmpPath, appPath)
|
||||||
if (fs.existsSync(downloadedPath)) {
|
if (fs.existsSync(downloadedPath)) {
|
||||||
|
|
|
@ -13,13 +13,13 @@ function generateAttachmentFindParams(
|
||||||
) {
|
) {
|
||||||
const params: CouchFindOptions = {
|
const params: CouchFindOptions = {
|
||||||
selector: {
|
selector: {
|
||||||
|
$or: attachmentCols.map(col => ({ [col]: { $exists: true } })),
|
||||||
_id: {
|
_id: {
|
||||||
$regex: `^${DocumentType.ROW}${SEPARATOR}${tableId}`,
|
$regex: `^${DocumentType.ROW}${SEPARATOR}${tableId}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
limit: FIND_LIMIT,
|
limit: FIND_LIMIT,
|
||||||
}
|
}
|
||||||
attachmentCols.forEach(col => (params.selector[col] = { $exists: true }))
|
|
||||||
if (bookmark) {
|
if (bookmark) {
|
||||||
params.bookmark = bookmark
|
params.bookmark = bookmark
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue