Review comments, renaming deployed -> prod in terms of app IDs.
This commit is contained in:
parent
1095ad17c6
commit
dbc048b365
|
@ -25,7 +25,7 @@ exports.isDevApp = app => {
|
|||
/**
|
||||
* Convert a development app ID to a deployed app ID.
|
||||
*/
|
||||
exports.getDeployedAppID = appId => {
|
||||
exports.getProdAppID = appId => {
|
||||
// if dev, convert it
|
||||
if (appId.startsWith(APP_DEV_PREFIX)) {
|
||||
const id = appId.split(APP_DEV_PREFIX)[1]
|
||||
|
|
|
@ -23,7 +23,7 @@ const {
|
|||
isProdAppID,
|
||||
isDevAppID,
|
||||
getDevelopmentAppID,
|
||||
getDeployedAppID,
|
||||
getProdAppID,
|
||||
} = require("./conversions")
|
||||
|
||||
const UNICODE_MAX = "\ufff0"
|
||||
|
@ -43,7 +43,7 @@ exports.isDevApp = isDevApp
|
|||
exports.isProdAppID = isProdAppID
|
||||
exports.isDevAppID = isDevAppID
|
||||
exports.getDevelopmentAppID = getDevelopmentAppID
|
||||
exports.getDeployedAppID = getDeployedAppID
|
||||
exports.getProdAppID = getProdAppID
|
||||
|
||||
/**
|
||||
* If creating DB allDocs/query params with only a single top level ID this can be used, this
|
||||
|
@ -197,7 +197,7 @@ exports.getAllDbs = async () => {
|
|||
}
|
||||
let couchUrl = `${exports.getCouchUrl()}/_all_dbs`
|
||||
let tenantId = getTenantId()
|
||||
if (!env.MULTI_TENANCY || tenantId == DEFAULT_TENANT_ID) {
|
||||
if (!env.MULTI_TENANCY || tenantId === DEFAULT_TENANT_ID) {
|
||||
// just get all DBs when:
|
||||
// - single tenancy
|
||||
// - default tenant
|
||||
|
@ -281,7 +281,7 @@ exports.getAllApps = async ({ dev, all, idsOnly } = {}) => {
|
|||
/**
|
||||
* Utility function for getAllApps but filters to production apps only.
|
||||
*/
|
||||
exports.getDeployedAppIDs = async () => {
|
||||
exports.getProdAppIDs = async () => {
|
||||
return (await exports.getAllApps({ idsOnly: true })).filter(
|
||||
id => !exports.isDevAppID(id)
|
||||
)
|
||||
|
|
|
@ -2,7 +2,7 @@ const env = require("../environment")
|
|||
const { Headers } = require("../../constants")
|
||||
const cls = require("./FunctionContext")
|
||||
const { getCouch } = require("../db")
|
||||
const { getDeployedAppID, getDevelopmentAppID } = require("../db/conversions")
|
||||
const { getProdAppID, getDevelopmentAppID } = require("../db/conversions")
|
||||
const { isEqual } = require("lodash")
|
||||
|
||||
// some test cases call functions directly, need to
|
||||
|
@ -150,7 +150,7 @@ function getDB(key, opts) {
|
|||
toUseAppId = appId
|
||||
break
|
||||
case ContextKeys.PROD_DB:
|
||||
toUseAppId = getDeployedAppID(appId)
|
||||
toUseAppId = getProdAppID(appId)
|
||||
break
|
||||
case ContextKeys.DEV_DB:
|
||||
toUseAppId = getDevelopmentAppID(appId)
|
||||
|
|
|
@ -28,7 +28,7 @@ const { processObject } = require("@budibase/string-templates")
|
|||
const {
|
||||
getAllApps,
|
||||
isDevAppID,
|
||||
getDeployedAppID,
|
||||
getProdAppID,
|
||||
Replication,
|
||||
} = require("@budibase/backend-core/db")
|
||||
const { USERS_TABLE_SCHEMA } = require("../../constants")
|
||||
|
@ -44,13 +44,17 @@ const { getTenantId, isMultiTenant } = require("@budibase/backend-core/tenancy")
|
|||
const { syncGlobalUsers } = require("./user")
|
||||
const { app: appCache } = require("@budibase/backend-core/cache")
|
||||
const { cleanupAutomations } = require("../../automations/utils")
|
||||
const context = require("@budibase/backend-core/context")
|
||||
const {
|
||||
getAppDB,
|
||||
getProdAppDB,
|
||||
updateAppId,
|
||||
} = require("@budibase/backend-core/context")
|
||||
|
||||
const URL_REGEX_SLASH = /\/|\\/g
|
||||
|
||||
// utility function, need to do away with this
|
||||
async function getLayouts() {
|
||||
const db = context.getAppDB()
|
||||
const db = getAppDB()
|
||||
return (
|
||||
await db.allDocs(
|
||||
getLayoutParams(null, {
|
||||
|
@ -61,7 +65,7 @@ async function getLayouts() {
|
|||
}
|
||||
|
||||
async function getScreens() {
|
||||
const db = context.getAppDB()
|
||||
const db = getAppDB()
|
||||
return (
|
||||
await db.allDocs(
|
||||
getScreenParams(null, {
|
||||
|
@ -119,9 +123,9 @@ async function createInstance(template) {
|
|||
const tenantId = isMultiTenant() ? getTenantId() : null
|
||||
const baseAppId = generateAppID(tenantId)
|
||||
const appId = generateDevAppID(baseAppId)
|
||||
context.updateAppId(appId)
|
||||
updateAppId(appId)
|
||||
|
||||
const db = context.getAppDB()
|
||||
const db = getAppDB()
|
||||
await db.put({
|
||||
_id: "_design/database",
|
||||
// view collation information, read before writing any complex views:
|
||||
|
@ -197,7 +201,7 @@ exports.fetchAppDefinition = async ctx => {
|
|||
}
|
||||
|
||||
exports.fetchAppPackage = async ctx => {
|
||||
const db = context.getAppDB()
|
||||
const db = getAppDB()
|
||||
const application = await db.get(DocumentTypes.APP_METADATA)
|
||||
const layouts = await getLayouts()
|
||||
let screens = await getScreens()
|
||||
|
@ -236,7 +240,7 @@ exports.create = async ctx => {
|
|||
const instance = await createInstance(instanceConfig)
|
||||
const appId = instance._id
|
||||
|
||||
const db = context.getAppDB()
|
||||
const db = getAppDB()
|
||||
let _rev
|
||||
try {
|
||||
// if template there will be an existing doc
|
||||
|
@ -301,7 +305,7 @@ exports.update = async ctx => {
|
|||
|
||||
exports.updateClient = async ctx => {
|
||||
// Get current app version
|
||||
const db = context.getAppDB()
|
||||
const db = getAppDB()
|
||||
const application = await db.get(DocumentTypes.APP_METADATA)
|
||||
const currentVersion = application.version
|
||||
|
||||
|
@ -323,7 +327,7 @@ exports.updateClient = async ctx => {
|
|||
|
||||
exports.revertClient = async ctx => {
|
||||
// Check app can be reverted
|
||||
const db = context.getAppDB()
|
||||
const db = getAppDB()
|
||||
const application = await db.get(DocumentTypes.APP_METADATA)
|
||||
if (!application.revertableVersion) {
|
||||
ctx.throw(400, "There is no version to revert to")
|
||||
|
@ -345,7 +349,7 @@ exports.revertClient = async ctx => {
|
|||
}
|
||||
|
||||
exports.delete = async ctx => {
|
||||
const db = context.getAppDB()
|
||||
const db = getAppDB()
|
||||
|
||||
const result = await db.destroy()
|
||||
/* istanbul ignore next */
|
||||
|
@ -370,11 +374,11 @@ exports.sync = async (ctx, next) => {
|
|||
}
|
||||
|
||||
// replicate prod to dev
|
||||
const prodAppId = getDeployedAppID(appId)
|
||||
const prodAppId = getProdAppID(appId)
|
||||
|
||||
try {
|
||||
// specific case, want to make sure setup is skipped
|
||||
const prodDb = context.getProdAppDB({ skip_setup: true })
|
||||
const prodDb = getProdAppDB({ skip_setup: true })
|
||||
const info = await prodDb.info()
|
||||
if (info.error) throw info.error
|
||||
} catch (err) {
|
||||
|
@ -414,7 +418,7 @@ exports.sync = async (ctx, next) => {
|
|||
}
|
||||
|
||||
const updateAppPackage = async (appPackage, appId) => {
|
||||
const db = context.getAppDB()
|
||||
const db = getAppDB()
|
||||
const application = await db.get(DocumentTypes.APP_METADATA)
|
||||
|
||||
const newAppPackage = { ...application, ...appPackage }
|
||||
|
@ -433,7 +437,7 @@ const updateAppPackage = async (appPackage, appId) => {
|
|||
}
|
||||
|
||||
const createEmptyAppPackage = async (ctx, app) => {
|
||||
const db = context.getAppDB()
|
||||
const db = getAppDB()
|
||||
|
||||
let screensAndLayouts = []
|
||||
for (let layout of BASE_LAYOUTS) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const Deployment = require("./Deployment")
|
||||
const {
|
||||
Replication,
|
||||
getDeployedAppID,
|
||||
getProdAppID,
|
||||
getDevelopmentAppID,
|
||||
} = require("@budibase/backend-core/db")
|
||||
const { DocumentTypes, getAutomationParams } = require("../../../db/utils")
|
||||
|
@ -97,7 +97,7 @@ async function deployApp(deployment) {
|
|||
try {
|
||||
const appId = getAppId()
|
||||
const devAppId = getDevelopmentAppID(appId)
|
||||
const productionAppId = getDeployedAppID(appId)
|
||||
const productionAppId = getProdAppID(appId)
|
||||
|
||||
const replication = new Replication({
|
||||
source: devAppId,
|
||||
|
|
|
@ -3,7 +3,7 @@ const env = require("../../environment")
|
|||
const { checkSlashesInUrl } = require("../../utilities")
|
||||
const { request } = require("../../utilities/workerRequests")
|
||||
const { clearLock } = require("../../utilities/redis")
|
||||
const { Replication, getDeployedAppID } = require("@budibase/backend-core/db")
|
||||
const { Replication, getProdAppID } = require("@budibase/backend-core/db")
|
||||
const { DocumentTypes } = require("../../db/utils")
|
||||
const { app: appCache } = require("@budibase/backend-core/cache")
|
||||
const { getProdAppDB, getAppDB } = require("@budibase/backend-core/context")
|
||||
|
@ -77,7 +77,7 @@ exports.clearLock = async ctx => {
|
|||
|
||||
exports.revert = async ctx => {
|
||||
const { appId } = ctx.params
|
||||
const productionAppId = getDeployedAppID(appId)
|
||||
const productionAppId = getProdAppID(appId)
|
||||
|
||||
// App must have been deployed first
|
||||
try {
|
||||
|
|
|
@ -10,7 +10,7 @@ const { isEqual } = require("lodash")
|
|||
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
|
||||
const {
|
||||
getDevelopmentAppID,
|
||||
getDeployedAppIDs,
|
||||
getProdAppIDs,
|
||||
dbExists,
|
||||
} = require("@budibase/backend-core/db")
|
||||
const { UserStatus } = require("@budibase/backend-core/constants")
|
||||
|
@ -92,7 +92,7 @@ exports.syncUser = async function (ctx) {
|
|||
let prodAppIds
|
||||
// if they are a builder then get all production app IDs
|
||||
if ((user.builder && user.builder.global) || deleting) {
|
||||
prodAppIds = await getDeployedAppIDs()
|
||||
prodAppIds = await getProdAppIDs()
|
||||
} else {
|
||||
prodAppIds = Object.entries(roles)
|
||||
.filter(entry => entry[1] !== BUILTIN_ROLE_IDS.PUBLIC)
|
||||
|
|
|
@ -2,7 +2,7 @@ const { generateWebhookID, getWebhookParams } = require("../../db/utils")
|
|||
const toJsonSchema = require("to-json-schema")
|
||||
const validate = require("jsonschema").validate
|
||||
const triggers = require("../../automations/triggers")
|
||||
const { getDeployedAppID } = require("@budibase/backend-core/db")
|
||||
const { getProdAppID } = require("@budibase/backend-core/db")
|
||||
const { getAppDB, updateAppId } = require("@budibase/backend-core/context")
|
||||
|
||||
const AUTOMATION_DESCRIPTION = "Generated from Webhook Schema"
|
||||
|
@ -82,8 +82,8 @@ exports.buildSchema = async ctx => {
|
|||
}
|
||||
|
||||
exports.trigger = async ctx => {
|
||||
const deployedAppId = getDeployedAppID(ctx.params.instance)
|
||||
updateAppId(deployedAppId)
|
||||
const prodAppId = getProdAppID(ctx.params.instance)
|
||||
updateAppId(prodAppId)
|
||||
try {
|
||||
const db = getAppDB()
|
||||
const webhook = await db.get(ctx.params.id)
|
||||
|
@ -98,7 +98,7 @@ exports.trigger = async ctx => {
|
|||
await triggers.externalTrigger(target, {
|
||||
body: ctx.request.body,
|
||||
...ctx.request.body,
|
||||
appId: deployedAppId,
|
||||
appId: prodAppId,
|
||||
})
|
||||
}
|
||||
ctx.status = 200
|
||||
|
|
|
@ -6,7 +6,7 @@ const { queue } = require("./bullboard")
|
|||
const newid = require("../db/newid")
|
||||
const { updateEntityMetadata } = require("../utilities")
|
||||
const { MetadataTypes } = require("../constants")
|
||||
const { getDeployedAppID } = require("@budibase/backend-core/db")
|
||||
const { getProdAppID } = require("@budibase/backend-core/db")
|
||||
const { cloneDeep } = require("lodash/fp")
|
||||
const { getAppDB, getAppId } = require("@budibase/backend-core/context")
|
||||
|
||||
|
@ -170,7 +170,7 @@ exports.checkForWebhooks = async ({ oldAuto, newAuto }) => {
|
|||
// the app ID has to be development for this endpoint
|
||||
// it can only be used when building the app
|
||||
// but the trigger endpoint will always be used in production
|
||||
const prodAppId = getDeployedAppID(appId)
|
||||
const prodAppId = getProdAppID(appId)
|
||||
newTrigger.inputs = {
|
||||
schemaUrl: `api/webhooks/schema/${appId}/${id}`,
|
||||
triggerUrl: `api/webhooks/trigger/${prodAppId}/${id}`,
|
||||
|
|
|
@ -3,7 +3,7 @@ const {
|
|||
getGlobalIDFromUserMetadataID,
|
||||
} = require("../db/utils")
|
||||
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
|
||||
const { getDeployedAppID } = require("@budibase/backend-core/db")
|
||||
const { getProdAppID } = require("@budibase/backend-core/db")
|
||||
const { getGlobalUserParams } = require("@budibase/backend-core/db")
|
||||
const { user: userCache } = require("@budibase/backend-core/cache")
|
||||
const {
|
||||
|
@ -26,7 +26,7 @@ exports.updateAppRole = (user, { appId } = {}) => {
|
|||
return user
|
||||
}
|
||||
// always use the deployed app
|
||||
user.roleId = user.roles[getDeployedAppID(appId)]
|
||||
user.roleId = user.roles[getProdAppID(appId)]
|
||||
// if a role wasn't found then either set as admin (builder) or public (everyone else)
|
||||
if (!user.roleId && user.builder && user.builder.global) {
|
||||
user.roleId = BUILTIN_ROLE_IDS.ADMIN
|
||||
|
|
|
@ -7,7 +7,7 @@ const { deleteFiles } = require("../../utilities/fileSystem/utilities")
|
|||
const { ObjectStoreBuckets } = require("../../constants")
|
||||
const {
|
||||
isProdAppID,
|
||||
getDeployedAppID,
|
||||
getProdAppID,
|
||||
dbExists,
|
||||
} = require("@budibase/backend-core/db")
|
||||
const { getAppId } = require("@budibase/backend-core/context")
|
||||
|
@ -303,7 +303,7 @@ exports.outputProcessing = async (table, rows, opts = { squash: true }) => {
|
|||
exports.cleanupAttachments = async (table, { row, rows, oldRow, oldTable }) => {
|
||||
const appId = getAppId()
|
||||
if (!isProdAppID(appId)) {
|
||||
const prodAppId = getDeployedAppID(appId)
|
||||
const prodAppId = getProdAppID(appId)
|
||||
// if prod exists, then don't allow deleting
|
||||
const exists = await dbExists(prodAppId)
|
||||
if (exists) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const fetch = require("node-fetch")
|
||||
const env = require("../environment")
|
||||
const { checkSlashesInUrl } = require("./index")
|
||||
const { getDeployedAppID } = require("@budibase/backend-core/db")
|
||||
const { getProdAppID } = require("@budibase/backend-core/db")
|
||||
const { updateAppRole } = require("./global")
|
||||
const { Headers } = require("@budibase/backend-core/constants")
|
||||
const { getTenantId, isTenantIdSet } = require("@budibase/backend-core/tenancy")
|
||||
|
@ -76,9 +76,9 @@ exports.getGlobalSelf = async (ctx, appId = null) => {
|
|||
}
|
||||
|
||||
exports.removeAppFromUserRoles = async (ctx, appId) => {
|
||||
const deployedAppId = getDeployedAppID(appId)
|
||||
const prodAppId = getProdAppID(appId)
|
||||
const response = await fetch(
|
||||
checkSlashesInUrl(env.WORKER_URL + `/api/global/roles/${deployedAppId}`),
|
||||
checkSlashesInUrl(env.WORKER_URL + `/api/global/roles/${prodAppId}`),
|
||||
request(ctx, {
|
||||
method: "DELETE",
|
||||
})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const { getAllRoles } = require("@budibase/backend-core/roles")
|
||||
const {
|
||||
getAllApps,
|
||||
getDeployedAppID,
|
||||
getProdAppID,
|
||||
DocumentTypes,
|
||||
} = require("@budibase/backend-core/db")
|
||||
const { doInAppContext, getAppDB } = require("@budibase/backend-core/context")
|
||||
|
@ -18,7 +18,7 @@ exports.fetch = async ctx => {
|
|||
const roles = await Promise.all(promises)
|
||||
const response = {}
|
||||
for (let app of apps) {
|
||||
const deployedAppId = getDeployedAppID(app.appId)
|
||||
const deployedAppId = getProdAppID(app.appId)
|
||||
response[deployedAppId] = {
|
||||
roles: roles.shift(),
|
||||
name: app.name,
|
||||
|
|
Loading…
Reference in New Issue