Final cleanup, just need to handle view migration (to self host from cloud).

This commit is contained in:
mike12345567 2021-09-29 17:43:16 +01:00
parent a0f69251c8
commit 94737c6574
3 changed files with 23 additions and 6 deletions

View File

@ -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

View File

@ -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.",
}

View File

@ -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.
*/