Moving things around ready for implementation of temp db handle.

This commit is contained in:
mike12345567 2023-09-19 18:38:44 +01:00
parent e408de539a
commit 8e0cf1d087
3 changed files with 38 additions and 5 deletions

View File

@ -39,9 +39,8 @@ import {
} from "../../db/defaultData/datasource_bb_default"
import { removeAppFromUserRoles } from "../../utilities/workerRequests"
import { stringToReadStream } from "../../utilities"
import { doesUserHaveLock, getLocksById } from "../../utilities/redis"
import { doesUserHaveLock } from "../../utilities/redis"
import { cleanupAutomations } from "../../automations/utils"
import { checkAppMetadata } from "../../automations/logging"
import { getUniqueRows } from "../../utilities/usageQuota/rows"
import { groups, licensing, quotas } from "@budibase/pro"
import {
@ -51,7 +50,6 @@ import {
PlanType,
Screen,
UserCtx,
ContextUser,
} from "@budibase/types"
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
import sdk from "../../sdk"
@ -578,11 +576,15 @@ export async function sync(ctx: UserCtx) {
export async function importToApp(ctx: UserCtx) {
const { appId } = ctx.params
const appExport = ctx.request.files?.appExport
const password = ctx.request.body.encryptionPassword
const password = ctx.request.body.encryptionPassword as string
if (!appExport) {
ctx.throw(400, "Must supply app export to import")
}
console.log(appExport)
if (Array.isArray(appExport)) {
ctx.throw(400, "Must only supply one app export")
}
const fileAttributes = { type: appExport.type!, path: appExport.path! }
await sdk.applications.updateWithExport(appId, fileAttributes, password)
ctx.body = { message: "app updated" }
}

View File

@ -0,0 +1,29 @@
import { db as dbCore } from "@budibase/backend-core"
import backups from "../backups"
export type FileAttributes = {
type: string
path: string
}
export async function updateWithExport(
appId: string,
file: FileAttributes,
password?: string
) {
const devId = dbCore.getDevAppID(appId)
// TEMPORARY BEGIN
const appDb = dbCore.getDB(devId)
await appDb.destroy()
// TEMPORARY END
// const tempAppName = `temp_${devId}`
// const tempDb = dbCore.getDB(tempAppName)
const template = {
file: {
type: file.type!,
path: file.path!,
password,
},
}
await backups.importApp(devId, appDb, template)
}

View File

@ -1,9 +1,11 @@
import * as sync from "./sync"
import * as utils from "./utils"
import * as applications from "./applications"
import * as imports from "./import"
export default {
...sync,
...utils,
...applications,
...imports,
}