Final cleanup, just need to handle view migration (to self host from cloud).
This commit is contained in:
parent
f69469ea4f
commit
ccd2913857
|
@ -1,7 +1,6 @@
|
|||
<script>
|
||||
import { notifications, ModalContent, Dropzone, Body } from "@budibase/bbui"
|
||||
import { post } from "builderStore/api"
|
||||
import { goto } from "@roxi/routify"
|
||||
|
||||
let submitting = false
|
||||
|
||||
|
@ -21,8 +20,8 @@
|
|||
if (!importResp.ok) {
|
||||
throw new Error(importJson.message)
|
||||
}
|
||||
// now login
|
||||
$goto("../auth")
|
||||
// now reload to get to login
|
||||
window.location.reload()
|
||||
} catch (error) {
|
||||
notifications.error(error)
|
||||
submitting = false
|
||||
|
|
|
@ -9,6 +9,7 @@ const {
|
|||
const { stringToReadStream } = require("../../utilities")
|
||||
const { getGlobalDBName, getGlobalDB } = require("@budibase/auth/tenancy")
|
||||
const { create } = require("./application")
|
||||
const { getDocParams, DocumentTypes } = require("../../db/utils")
|
||||
|
||||
async function createApp(appName, appImport) {
|
||||
const ctx = {
|
||||
|
@ -39,6 +40,15 @@ exports.exportApps = async ctx => {
|
|||
ctx.body = sendTempFile(JSON.stringify(allDBs))
|
||||
}
|
||||
|
||||
async function getAllDocType(db, docType) {
|
||||
const response = await db.allDocs(
|
||||
getDocParams(docType, null, {
|
||||
include_docs: true,
|
||||
})
|
||||
)
|
||||
return response.rows.map(row => row.doc)
|
||||
}
|
||||
|
||||
exports.importApps = async ctx => {
|
||||
if (!env.SELF_HOSTED || env.MULTI_TENANCY) {
|
||||
ctx.throw(400, "Importing only allowed in self hosted environments.")
|
||||
|
@ -57,15 +67,21 @@ exports.importApps = async ctx => {
|
|||
const importFile = ctx.request.files.importFile
|
||||
const importString = readFileSync(importFile.path)
|
||||
const dbs = JSON.parse(importString)
|
||||
const globalDb = dbs.global
|
||||
const globalDbImport = dbs.global
|
||||
// remove from the list of apps
|
||||
delete dbs.global
|
||||
const db = getGlobalDB()
|
||||
const globalDb = getGlobalDB()
|
||||
// load the global db first
|
||||
await db.load(stringToReadStream(globalDb))
|
||||
await globalDb.load(stringToReadStream(globalDbImport))
|
||||
for (let [appName, appImport] of Object.entries(dbs)) {
|
||||
await createApp(appName, appImport)
|
||||
}
|
||||
// once apps are created clean up the global db
|
||||
let users = await getAllDocType(globalDb, DocumentTypes.USER)
|
||||
for (let user of users) {
|
||||
delete user.tenantId
|
||||
}
|
||||
await globalDb.bulkDocs(users)
|
||||
ctx.body = {
|
||||
message: "Apps successfully imported.",
|
||||
}
|
||||
|
|
|
@ -110,6 +110,8 @@ function getDocParams(docType, docId = null, otherProps = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
exports.getDocParams = getDocParams
|
||||
|
||||
/**
|
||||
* Gets parameters for retrieving tables, this is a utility function for the getDocParams function.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue