Merge branch 'fix/apps-2195-2282-2283' of github.com:Budibase/budibase into develop
This commit is contained in:
commit
88396b77ed
|
@ -5,7 +5,7 @@ version: "3"
|
||||||
services:
|
services:
|
||||||
app-service:
|
app-service:
|
||||||
restart: always
|
restart: always
|
||||||
image: budibase/apps
|
image: budibase.docker.scarf.sh/budibase/apps
|
||||||
container_name: bbapps
|
container_name: bbapps
|
||||||
ports:
|
ports:
|
||||||
- "${APP_PORT}:4002"
|
- "${APP_PORT}:4002"
|
||||||
|
@ -33,7 +33,7 @@ services:
|
||||||
|
|
||||||
worker-service:
|
worker-service:
|
||||||
restart: always
|
restart: always
|
||||||
image: budibase/worker
|
image: budibase.docker.scarf.sh/budibase/worker
|
||||||
container_name: bbworker
|
container_name: bbworker
|
||||||
ports:
|
ports:
|
||||||
- "${WORKER_PORT}:4003"
|
- "${WORKER_PORT}:4003"
|
||||||
|
|
|
@ -4,6 +4,8 @@ const { DEFAULT_TENANT_ID } = require("../constants")
|
||||||
const env = require("../environment")
|
const env = require("../environment")
|
||||||
const { StaticDatabases, SEPARATOR } = require("./constants")
|
const { StaticDatabases, SEPARATOR } = require("./constants")
|
||||||
const { getTenantId } = require("../tenancy")
|
const { getTenantId } = require("../tenancy")
|
||||||
|
const fetch = require("node-fetch")
|
||||||
|
const { getCouch } = require("./index")
|
||||||
|
|
||||||
const UNICODE_MAX = "\ufff0"
|
const UNICODE_MAX = "\ufff0"
|
||||||
|
|
||||||
|
@ -156,6 +158,23 @@ exports.getDeployedAppID = appId => {
|
||||||
return appId
|
return appId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if in production this will use the CouchDB _all_dbs call to retrieve a list of databases. If testing
|
||||||
|
* when using Pouch it will use the pouchdb-all-dbs package.
|
||||||
|
*/
|
||||||
|
exports.getAllDbs = async () => {
|
||||||
|
// specifically for testing we use the pouch package for this
|
||||||
|
if (env.isTest()) {
|
||||||
|
return getCouch().allDbs()
|
||||||
|
}
|
||||||
|
const response = await fetch(`${env.COUCH_DB_URL}/_all_dbs`)
|
||||||
|
if (response.status === 200) {
|
||||||
|
return response.json()
|
||||||
|
} else {
|
||||||
|
throw "Cannot connect to CouchDB instance"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lots of different points in the system need to find the full list of apps, this will
|
* Lots of different points in the system need to find the full list of apps, this will
|
||||||
* enumerate the entire CouchDB cluster and get the list of databases (every app).
|
* enumerate the entire CouchDB cluster and get the list of databases (every app).
|
||||||
|
@ -163,13 +182,13 @@ exports.getDeployedAppID = appId => {
|
||||||
* different users/companies apps as there is no security around it - all apps are returned.
|
* different users/companies apps as there is no security around it - all apps are returned.
|
||||||
* @return {Promise<object[]>} returns the app information document stored in each app database.
|
* @return {Promise<object[]>} returns the app information document stored in each app database.
|
||||||
*/
|
*/
|
||||||
exports.getAllApps = async (CouchDB, { dev, all } = {}) => {
|
exports.getAllApps = async (CouchDB, { dev, all, idsOnly } = {}) => {
|
||||||
let tenantId = getTenantId()
|
let tenantId = getTenantId()
|
||||||
if (!env.MULTI_TENANCY && !tenantId) {
|
if (!env.MULTI_TENANCY && !tenantId) {
|
||||||
tenantId = DEFAULT_TENANT_ID
|
tenantId = DEFAULT_TENANT_ID
|
||||||
}
|
}
|
||||||
let allDbs = await CouchDB.allDbs()
|
let dbs = await exports.getAllDbs()
|
||||||
const appDbNames = allDbs.filter(dbName => {
|
const appDbNames = dbs.filter(dbName => {
|
||||||
const split = dbName.split(SEPARATOR)
|
const split = dbName.split(SEPARATOR)
|
||||||
// it is an app, check the tenantId
|
// it is an app, check the tenantId
|
||||||
if (split[0] === DocumentTypes.APP) {
|
if (split[0] === DocumentTypes.APP) {
|
||||||
|
@ -183,6 +202,9 @@ exports.getAllApps = async (CouchDB, { dev, all } = {}) => {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
if (idsOnly) {
|
||||||
|
return appDbNames
|
||||||
|
}
|
||||||
const appPromises = appDbNames.map(db =>
|
const appPromises = appDbNames.map(db =>
|
||||||
// skip setup otherwise databases could be re-created
|
// skip setup otherwise databases could be re-created
|
||||||
new CouchDB(db, { skip_setup: true }).get(DocumentTypes.APP_METADATA)
|
new CouchDB(db, { skip_setup: true }).get(DocumentTypes.APP_METADATA)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
const PouchDB = require("pouchdb")
|
const PouchDB = require("pouchdb")
|
||||||
const allDbs = require("pouchdb-all-dbs")
|
|
||||||
const env = require("../../../../environment")
|
const env = require("../../../../environment")
|
||||||
|
|
||||||
let POUCH_DB_DEFAULTS
|
let POUCH_DB_DEFAULTS
|
||||||
|
@ -15,6 +14,4 @@ if (env.isTest()) {
|
||||||
|
|
||||||
const Pouch = PouchDB.defaults(POUCH_DB_DEFAULTS)
|
const Pouch = PouchDB.defaults(POUCH_DB_DEFAULTS)
|
||||||
|
|
||||||
allDbs(Pouch)
|
|
||||||
|
|
||||||
module.exports = Pouch
|
module.exports = Pouch
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
Checkbox,
|
Checkbox,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { store, automationStore, hostingStore } from "builderStore"
|
import { store, automationStore, hostingStore } from "builderStore"
|
||||||
|
import { admin } from "stores/portal"
|
||||||
import { string, mixed, object } from "yup"
|
import { string, mixed, object } from "yup"
|
||||||
import api, { get, post } from "builderStore/api"
|
import api, { get, post } from "builderStore/api"
|
||||||
import analytics from "analytics"
|
import analytics from "analytics"
|
||||||
|
@ -102,6 +103,8 @@
|
||||||
if (applicationPkg.ok) {
|
if (applicationPkg.ok) {
|
||||||
await store.actions.initialise(pkg)
|
await store.actions.initialise(pkg)
|
||||||
await automationStore.actions.fetch()
|
await automationStore.actions.fetch()
|
||||||
|
// update checklist - incase first app
|
||||||
|
await admin.init()
|
||||||
} else {
|
} else {
|
||||||
throw new Error(pkg)
|
throw new Error(pkg)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
import api, { del } from "builderStore/api"
|
import api, { del } from "builderStore/api"
|
||||||
import analytics from "analytics"
|
import analytics from "analytics"
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import { apps, auth } from "stores/portal"
|
import { apps, auth, admin } from "stores/portal"
|
||||||
import download from "downloadjs"
|
import download from "downloadjs"
|
||||||
import { goto } from "@roxi/routify"
|
import { goto } from "@roxi/routify"
|
||||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||||
|
@ -159,6 +159,8 @@
|
||||||
throw json.message
|
throw json.message
|
||||||
}
|
}
|
||||||
await apps.load()
|
await apps.load()
|
||||||
|
// get checklist, just in case that was the last app
|
||||||
|
await admin.init()
|
||||||
notifications.success("App deleted successfully")
|
notifications.success("App deleted successfully")
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
notifications.error(`Error deleting app: ${err}`)
|
notifications.error(`Error deleting app: ${err}`)
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
const CouchDB = require("../src/db")
|
const CouchDB = require("../src/db")
|
||||||
const { DocumentTypes } = require("../src/db/utils")
|
const { DocumentTypes } = require("../src/db/utils")
|
||||||
|
const { getAllDbs } = require("@budibase/auth/db")
|
||||||
|
|
||||||
const appName = process.argv[2].toLowerCase()
|
const appName = process.argv[2].toLowerCase()
|
||||||
const remoteUrl = process.argv[3]
|
const remoteUrl = process.argv[3]
|
||||||
|
@ -14,8 +15,8 @@ const remoteUrl = process.argv[3]
|
||||||
console.log(`Replicating from ${appName} to ${remoteUrl}/${appName}`)
|
console.log(`Replicating from ${appName} to ${remoteUrl}/${appName}`)
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
const allDbs = await CouchDB.allDbs()
|
const dbs = await getAllDbs()
|
||||||
const appDbNames = allDbs.filter(dbName => dbName.startsWith("inst_app"))
|
const appDbNames = dbs.filter(dbName => dbName.startsWith("inst_app"))
|
||||||
let apps = []
|
let apps = []
|
||||||
for (let dbName of appDbNames) {
|
for (let dbName of appDbNames) {
|
||||||
const db = new CouchDB(dbName)
|
const db = new CouchDB(dbName)
|
||||||
|
|
|
@ -24,21 +24,7 @@ if (env.isTest()) {
|
||||||
|
|
||||||
const Pouch = PouchDB.defaults(POUCH_DB_DEFAULTS)
|
const Pouch = PouchDB.defaults(POUCH_DB_DEFAULTS)
|
||||||
|
|
||||||
|
// have to still have pouch alldbs for testing
|
||||||
allDbs(Pouch)
|
allDbs(Pouch)
|
||||||
|
|
||||||
// replicate your local levelDB pouch to a running HTTP compliant couch or pouchdb server.
|
|
||||||
/* istanbul ignore next */
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
|
||||||
function replicateLocal() {
|
|
||||||
Pouch.allDbs().then(dbs => {
|
|
||||||
for (let db of dbs) {
|
|
||||||
new Pouch(db).sync(
|
|
||||||
new PouchDB(`http://127.0.0.1:5984/${db}`, { live: true })
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// replicateLocal()
|
|
||||||
|
|
||||||
module.exports = Pouch
|
module.exports = Pouch
|
||||||
|
|
|
@ -4,14 +4,9 @@ const CouchDB = require("../../db")
|
||||||
const URL_REGEX_SLASH = /\/|\\/g
|
const URL_REGEX_SLASH = /\/|\\/g
|
||||||
|
|
||||||
exports.getApps = async ctx => {
|
exports.getApps = async ctx => {
|
||||||
const tenantId = ctx.user.tenantId
|
const apps = await getAllApps(CouchDB, { dev: true })
|
||||||
const apps = await getAllApps(CouchDB, { tenantId })
|
|
||||||
|
|
||||||
const body = {}
|
const body = {}
|
||||||
for (let app of apps) {
|
for (let app of apps) {
|
||||||
if (app.status !== "fulfilled") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
app = app.value
|
app = app.value
|
||||||
let url = app.url || encodeURI(`${app.name}`)
|
let url = app.url || encodeURI(`${app.name}`)
|
||||||
url = `/${url.replace(URL_REGEX_SLASH, "")}`
|
url = `/${url.replace(URL_REGEX_SLASH, "")}`
|
||||||
|
|
|
@ -223,7 +223,7 @@ exports.configChecklist = async function (ctx) {
|
||||||
// TODO: Watch get started video
|
// TODO: Watch get started video
|
||||||
|
|
||||||
// Apps exist
|
// Apps exist
|
||||||
const apps = await getAllApps(CouchDB)
|
const apps = await getAllApps(CouchDB, { idsOnly: true })
|
||||||
|
|
||||||
// They have set up SMTP
|
// They have set up SMTP
|
||||||
const smtpConfig = await getScopedFullConfig(db, {
|
const smtpConfig = await getScopedFullConfig(db, {
|
||||||
|
|
|
@ -19,6 +19,7 @@ if (env.isTest()) {
|
||||||
|
|
||||||
const Pouch = PouchDB.defaults(POUCH_DB_DEFAULTS)
|
const Pouch = PouchDB.defaults(POUCH_DB_DEFAULTS)
|
||||||
|
|
||||||
|
// have to still have pouch alldbs for testing
|
||||||
allDbs(Pouch)
|
allDbs(Pouch)
|
||||||
|
|
||||||
module.exports = Pouch
|
module.exports = Pouch
|
||||||
|
|
Loading…
Reference in New Issue