Moving things around ready for implementation of temp db handle.
This commit is contained in:
parent
e408de539a
commit
8e0cf1d087
|
@ -39,9 +39,8 @@ import {
|
||||||
} from "../../db/defaultData/datasource_bb_default"
|
} from "../../db/defaultData/datasource_bb_default"
|
||||||
import { removeAppFromUserRoles } from "../../utilities/workerRequests"
|
import { removeAppFromUserRoles } from "../../utilities/workerRequests"
|
||||||
import { stringToReadStream } from "../../utilities"
|
import { stringToReadStream } from "../../utilities"
|
||||||
import { doesUserHaveLock, getLocksById } from "../../utilities/redis"
|
import { doesUserHaveLock } from "../../utilities/redis"
|
||||||
import { cleanupAutomations } from "../../automations/utils"
|
import { cleanupAutomations } from "../../automations/utils"
|
||||||
import { checkAppMetadata } from "../../automations/logging"
|
|
||||||
import { getUniqueRows } from "../../utilities/usageQuota/rows"
|
import { getUniqueRows } from "../../utilities/usageQuota/rows"
|
||||||
import { groups, licensing, quotas } from "@budibase/pro"
|
import { groups, licensing, quotas } from "@budibase/pro"
|
||||||
import {
|
import {
|
||||||
|
@ -51,7 +50,6 @@ import {
|
||||||
PlanType,
|
PlanType,
|
||||||
Screen,
|
Screen,
|
||||||
UserCtx,
|
UserCtx,
|
||||||
ContextUser,
|
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
|
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
|
||||||
import sdk from "../../sdk"
|
import sdk from "../../sdk"
|
||||||
|
@ -578,11 +576,15 @@ export async function sync(ctx: UserCtx) {
|
||||||
export async function importToApp(ctx: UserCtx) {
|
export async function importToApp(ctx: UserCtx) {
|
||||||
const { appId } = ctx.params
|
const { appId } = ctx.params
|
||||||
const appExport = ctx.request.files?.appExport
|
const appExport = ctx.request.files?.appExport
|
||||||
const password = ctx.request.body.encryptionPassword
|
const password = ctx.request.body.encryptionPassword as string
|
||||||
if (!appExport) {
|
if (!appExport) {
|
||||||
ctx.throw(400, "Must supply app export to import")
|
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" }
|
ctx.body = { message: "app updated" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
|
@ -1,9 +1,11 @@
|
||||||
import * as sync from "./sync"
|
import * as sync from "./sync"
|
||||||
import * as utils from "./utils"
|
import * as utils from "./utils"
|
||||||
import * as applications from "./applications"
|
import * as applications from "./applications"
|
||||||
|
import * as imports from "./import"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
...sync,
|
...sync,
|
||||||
...utils,
|
...utils,
|
||||||
...applications,
|
...applications,
|
||||||
|
...imports,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue