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>
|
<script>
|
||||||
import { notifications, ModalContent, Dropzone, Body } from "@budibase/bbui"
|
import { notifications, ModalContent, Dropzone, Body } from "@budibase/bbui"
|
||||||
import { post } from "builderStore/api"
|
import { post } from "builderStore/api"
|
||||||
import { goto } from "@roxi/routify"
|
|
||||||
|
|
||||||
let submitting = false
|
let submitting = false
|
||||||
|
|
||||||
|
@ -21,8 +20,8 @@
|
||||||
if (!importResp.ok) {
|
if (!importResp.ok) {
|
||||||
throw new Error(importJson.message)
|
throw new Error(importJson.message)
|
||||||
}
|
}
|
||||||
// now login
|
// now reload to get to login
|
||||||
$goto("../auth")
|
window.location.reload()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notifications.error(error)
|
notifications.error(error)
|
||||||
submitting = false
|
submitting = false
|
||||||
|
|
|
@ -9,6 +9,7 @@ const {
|
||||||
const { stringToReadStream } = require("../../utilities")
|
const { stringToReadStream } = require("../../utilities")
|
||||||
const { getGlobalDBName, getGlobalDB } = require("@budibase/auth/tenancy")
|
const { getGlobalDBName, getGlobalDB } = require("@budibase/auth/tenancy")
|
||||||
const { create } = require("./application")
|
const { create } = require("./application")
|
||||||
|
const { getDocParams, DocumentTypes } = require("../../db/utils")
|
||||||
|
|
||||||
async function createApp(appName, appImport) {
|
async function createApp(appName, appImport) {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
|
@ -39,6 +40,15 @@ exports.exportApps = async ctx => {
|
||||||
ctx.body = sendTempFile(JSON.stringify(allDBs))
|
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 => {
|
exports.importApps = async ctx => {
|
||||||
if (!env.SELF_HOSTED || env.MULTI_TENANCY) {
|
if (!env.SELF_HOSTED || env.MULTI_TENANCY) {
|
||||||
ctx.throw(400, "Importing only allowed in self hosted environments.")
|
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 importFile = ctx.request.files.importFile
|
||||||
const importString = readFileSync(importFile.path)
|
const importString = readFileSync(importFile.path)
|
||||||
const dbs = JSON.parse(importString)
|
const dbs = JSON.parse(importString)
|
||||||
const globalDb = dbs.global
|
const globalDbImport = dbs.global
|
||||||
// remove from the list of apps
|
// remove from the list of apps
|
||||||
delete dbs.global
|
delete dbs.global
|
||||||
const db = getGlobalDB()
|
const globalDb = getGlobalDB()
|
||||||
// load the global db first
|
// load the global db first
|
||||||
await db.load(stringToReadStream(globalDb))
|
await globalDb.load(stringToReadStream(globalDbImport))
|
||||||
for (let [appName, appImport] of Object.entries(dbs)) {
|
for (let [appName, appImport] of Object.entries(dbs)) {
|
||||||
await createApp(appName, appImport)
|
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 = {
|
ctx.body = {
|
||||||
message: "Apps successfully imported.",
|
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.
|
* Gets parameters for retrieving tables, this is a utility function for the getDocParams function.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue