Fixing multi-app import from cloud.
This commit is contained in:
parent
d1c9a56e9a
commit
907b838db3
|
@ -3,15 +3,9 @@ const { getAllApps, getGlobalDBName } = require("@budibase/backend-core/db")
|
|||
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
||||
const { streamFile } = require("../../utilities/fileSystem")
|
||||
const { stringToReadStream } = require("../../utilities")
|
||||
const {
|
||||
getDocParams,
|
||||
DocumentType,
|
||||
isDevAppID,
|
||||
APP_PREFIX,
|
||||
} = require("../../db/utils")
|
||||
const { getDocParams, DocumentType, isDevAppID } = require("../../db/utils")
|
||||
const { create } = require("./application")
|
||||
const { join } = require("path")
|
||||
const fs = require("fs")
|
||||
const sdk = require("../../sdk")
|
||||
|
||||
async function createApp(appName, appDirectory) {
|
||||
|
@ -41,9 +35,9 @@ async function getAllDocType(db, docType) {
|
|||
}
|
||||
|
||||
exports.exportApps = async ctx => {
|
||||
if (env.SELF_HOSTED || !env.MULTI_TENANCY) {
|
||||
ctx.throw(400, "Exporting only allowed in multi-tenant cloud environments.")
|
||||
}
|
||||
// if (env.SELF_HOSTED || !env.MULTI_TENANCY) {
|
||||
// ctx.throw(400, "Exporting only allowed in multi-tenant cloud environments.")
|
||||
// }
|
||||
const apps = await getAllApps({ all: true })
|
||||
const globalDBString = await sdk.backups.exportDB(getGlobalDBName(), {
|
||||
filter: doc => !doc._id.startsWith(DocumentType.USER),
|
||||
|
@ -92,20 +86,16 @@ exports.importApps = async ctx => {
|
|||
}
|
||||
|
||||
// initially get all the app databases out of the tarball
|
||||
const tmpPath = sdk.backups.untarFile(ctx.request.file.importFile)
|
||||
const tmpPath = sdk.backups.untarFile(ctx.request.files.importFile)
|
||||
const globalDbImport = sdk.backups.getGlobalDBFile(tmpPath)
|
||||
const appNames = fs
|
||||
.readdirSync(tmpPath)
|
||||
.filter(dir => dir.startsWith(APP_PREFIX))
|
||||
const appNames = sdk.backups.getListOfAppsInMulti(tmpPath)
|
||||
|
||||
const globalDb = getGlobalDB()
|
||||
// load the global db first
|
||||
await globalDb.load(stringToReadStream(globalDbImport))
|
||||
const appCreationPromises = []
|
||||
for (let appName of appNames) {
|
||||
appCreationPromises.push(createApp(appName, join(tmpPath, appName)))
|
||||
await createApp(appName, join(tmpPath, appName))
|
||||
}
|
||||
await Promise.all(appCreationPromises)
|
||||
|
||||
// if there are any users make sure to remove them
|
||||
let users = await getAllDocType(globalDb, DocumentType.USER)
|
||||
|
|
|
@ -141,7 +141,7 @@ export async function exportMultipleApps(
|
|||
// export each app to a directory, then move it into the complete export
|
||||
const exportAndMove = async (appId: string, appName: string) => {
|
||||
const path = await exportApp(appId)
|
||||
await fs.promises.rename(path, join(tmpPath, appId))
|
||||
await fs.promises.rename(path, join(tmpPath, appName))
|
||||
}
|
||||
for (let metadata of appMetadata) {
|
||||
exportPromises.push(exportAndMove(metadata.appId, metadata.name))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { db as dbCore } from "@budibase/backend-core"
|
||||
import { TABLE_ROW_PREFIX } from "../../../db/utils"
|
||||
import { APP_PREFIX, TABLE_ROW_PREFIX } from "../../../db/utils"
|
||||
import { budibaseTempDir } from "../../../utilities/budibaseDir"
|
||||
import {
|
||||
DB_EXPORT_FILE,
|
||||
|
@ -111,6 +111,10 @@ export function getGlobalDBFile(tmpPath: string) {
|
|||
return fs.readFileSync(join(tmpPath, GLOBAL_DB_EXPORT_FILE), "utf8")
|
||||
}
|
||||
|
||||
export function getListOfAppsInMulti(tmpPath: string) {
|
||||
return fs.readdirSync(tmpPath).filter(dir => dir !== GLOBAL_DB_EXPORT_FILE)
|
||||
}
|
||||
|
||||
export async function importApp(
|
||||
appId: string,
|
||||
db: PouchDB.Database,
|
||||
|
|
Loading…
Reference in New Issue