Review comments, renaming deployed -> prod in terms of app IDs.

This commit is contained in:
mike12345567 2022-01-31 17:42:51 +00:00
parent 1095ad17c6
commit dbc048b365
13 changed files with 47 additions and 43 deletions

View File

@ -25,7 +25,7 @@ exports.isDevApp = app => {
/** /**
* Convert a development app ID to a deployed app ID. * Convert a development app ID to a deployed app ID.
*/ */
exports.getDeployedAppID = appId => { exports.getProdAppID = appId => {
// if dev, convert it // if dev, convert it
if (appId.startsWith(APP_DEV_PREFIX)) { if (appId.startsWith(APP_DEV_PREFIX)) {
const id = appId.split(APP_DEV_PREFIX)[1] const id = appId.split(APP_DEV_PREFIX)[1]

View File

@ -23,7 +23,7 @@ const {
isProdAppID, isProdAppID,
isDevAppID, isDevAppID,
getDevelopmentAppID, getDevelopmentAppID,
getDeployedAppID, getProdAppID,
} = require("./conversions") } = require("./conversions")
const UNICODE_MAX = "\ufff0" const UNICODE_MAX = "\ufff0"
@ -43,7 +43,7 @@ exports.isDevApp = isDevApp
exports.isProdAppID = isProdAppID exports.isProdAppID = isProdAppID
exports.isDevAppID = isDevAppID exports.isDevAppID = isDevAppID
exports.getDevelopmentAppID = getDevelopmentAppID 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 * 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 couchUrl = `${exports.getCouchUrl()}/_all_dbs`
let tenantId = getTenantId() let tenantId = getTenantId()
if (!env.MULTI_TENANCY || tenantId == DEFAULT_TENANT_ID) { if (!env.MULTI_TENANCY || tenantId === DEFAULT_TENANT_ID) {
// just get all DBs when: // just get all DBs when:
// - single tenancy // - single tenancy
// - default tenant // - default tenant
@ -281,7 +281,7 @@ exports.getAllApps = async ({ dev, all, idsOnly } = {}) => {
/** /**
* Utility function for getAllApps but filters to production apps only. * Utility function for getAllApps but filters to production apps only.
*/ */
exports.getDeployedAppIDs = async () => { exports.getProdAppIDs = async () => {
return (await exports.getAllApps({ idsOnly: true })).filter( return (await exports.getAllApps({ idsOnly: true })).filter(
id => !exports.isDevAppID(id) id => !exports.isDevAppID(id)
) )

View File

@ -2,7 +2,7 @@ const env = require("../environment")
const { Headers } = require("../../constants") const { Headers } = require("../../constants")
const cls = require("./FunctionContext") const cls = require("./FunctionContext")
const { getCouch } = require("../db") const { getCouch } = require("../db")
const { getDeployedAppID, getDevelopmentAppID } = require("../db/conversions") const { getProdAppID, getDevelopmentAppID } = require("../db/conversions")
const { isEqual } = require("lodash") const { isEqual } = require("lodash")
// some test cases call functions directly, need to // some test cases call functions directly, need to
@ -150,7 +150,7 @@ function getDB(key, opts) {
toUseAppId = appId toUseAppId = appId
break break
case ContextKeys.PROD_DB: case ContextKeys.PROD_DB:
toUseAppId = getDeployedAppID(appId) toUseAppId = getProdAppID(appId)
break break
case ContextKeys.DEV_DB: case ContextKeys.DEV_DB:
toUseAppId = getDevelopmentAppID(appId) toUseAppId = getDevelopmentAppID(appId)

View File

@ -28,7 +28,7 @@ const { processObject } = require("@budibase/string-templates")
const { const {
getAllApps, getAllApps,
isDevAppID, isDevAppID,
getDeployedAppID, getProdAppID,
Replication, Replication,
} = require("@budibase/backend-core/db") } = require("@budibase/backend-core/db")
const { USERS_TABLE_SCHEMA } = require("../../constants") const { USERS_TABLE_SCHEMA } = require("../../constants")
@ -44,13 +44,17 @@ const { getTenantId, isMultiTenant } = require("@budibase/backend-core/tenancy")
const { syncGlobalUsers } = require("./user") const { syncGlobalUsers } = require("./user")
const { app: appCache } = require("@budibase/backend-core/cache") const { app: appCache } = require("@budibase/backend-core/cache")
const { cleanupAutomations } = require("../../automations/utils") 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 const URL_REGEX_SLASH = /\/|\\/g
// utility function, need to do away with this // utility function, need to do away with this
async function getLayouts() { async function getLayouts() {
const db = context.getAppDB() const db = getAppDB()
return ( return (
await db.allDocs( await db.allDocs(
getLayoutParams(null, { getLayoutParams(null, {
@ -61,7 +65,7 @@ async function getLayouts() {
} }
async function getScreens() { async function getScreens() {
const db = context.getAppDB() const db = getAppDB()
return ( return (
await db.allDocs( await db.allDocs(
getScreenParams(null, { getScreenParams(null, {
@ -119,9 +123,9 @@ async function createInstance(template) {
const tenantId = isMultiTenant() ? getTenantId() : null const tenantId = isMultiTenant() ? getTenantId() : null
const baseAppId = generateAppID(tenantId) const baseAppId = generateAppID(tenantId)
const appId = generateDevAppID(baseAppId) const appId = generateDevAppID(baseAppId)
context.updateAppId(appId) updateAppId(appId)
const db = context.getAppDB() const db = getAppDB()
await db.put({ await db.put({
_id: "_design/database", _id: "_design/database",
// view collation information, read before writing any complex views: // view collation information, read before writing any complex views:
@ -197,7 +201,7 @@ exports.fetchAppDefinition = async ctx => {
} }
exports.fetchAppPackage = async ctx => { exports.fetchAppPackage = async ctx => {
const db = context.getAppDB() const db = getAppDB()
const application = await db.get(DocumentTypes.APP_METADATA) const application = await db.get(DocumentTypes.APP_METADATA)
const layouts = await getLayouts() const layouts = await getLayouts()
let screens = await getScreens() let screens = await getScreens()
@ -236,7 +240,7 @@ exports.create = async ctx => {
const instance = await createInstance(instanceConfig) const instance = await createInstance(instanceConfig)
const appId = instance._id const appId = instance._id
const db = context.getAppDB() const db = getAppDB()
let _rev let _rev
try { try {
// if template there will be an existing doc // if template there will be an existing doc
@ -301,7 +305,7 @@ exports.update = async ctx => {
exports.updateClient = async ctx => { exports.updateClient = async ctx => {
// Get current app version // Get current app version
const db = context.getAppDB() const db = getAppDB()
const application = await db.get(DocumentTypes.APP_METADATA) const application = await db.get(DocumentTypes.APP_METADATA)
const currentVersion = application.version const currentVersion = application.version
@ -323,7 +327,7 @@ exports.updateClient = async ctx => {
exports.revertClient = async ctx => { exports.revertClient = async ctx => {
// Check app can be reverted // Check app can be reverted
const db = context.getAppDB() const db = getAppDB()
const application = await db.get(DocumentTypes.APP_METADATA) const application = await db.get(DocumentTypes.APP_METADATA)
if (!application.revertableVersion) { if (!application.revertableVersion) {
ctx.throw(400, "There is no version to revert to") ctx.throw(400, "There is no version to revert to")
@ -345,7 +349,7 @@ exports.revertClient = async ctx => {
} }
exports.delete = async ctx => { exports.delete = async ctx => {
const db = context.getAppDB() const db = getAppDB()
const result = await db.destroy() const result = await db.destroy()
/* istanbul ignore next */ /* istanbul ignore next */
@ -370,11 +374,11 @@ exports.sync = async (ctx, next) => {
} }
// replicate prod to dev // replicate prod to dev
const prodAppId = getDeployedAppID(appId) const prodAppId = getProdAppID(appId)
try { try {
// specific case, want to make sure setup is skipped // 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() const info = await prodDb.info()
if (info.error) throw info.error if (info.error) throw info.error
} catch (err) { } catch (err) {
@ -414,7 +418,7 @@ exports.sync = async (ctx, next) => {
} }
const updateAppPackage = async (appPackage, appId) => { const updateAppPackage = async (appPackage, appId) => {
const db = context.getAppDB() const db = getAppDB()
const application = await db.get(DocumentTypes.APP_METADATA) const application = await db.get(DocumentTypes.APP_METADATA)
const newAppPackage = { ...application, ...appPackage } const newAppPackage = { ...application, ...appPackage }
@ -433,7 +437,7 @@ const updateAppPackage = async (appPackage, appId) => {
} }
const createEmptyAppPackage = async (ctx, app) => { const createEmptyAppPackage = async (ctx, app) => {
const db = context.getAppDB() const db = getAppDB()
let screensAndLayouts = [] let screensAndLayouts = []
for (let layout of BASE_LAYOUTS) { for (let layout of BASE_LAYOUTS) {

View File

@ -1,7 +1,7 @@
const Deployment = require("./Deployment") const Deployment = require("./Deployment")
const { const {
Replication, Replication,
getDeployedAppID, getProdAppID,
getDevelopmentAppID, getDevelopmentAppID,
} = require("@budibase/backend-core/db") } = require("@budibase/backend-core/db")
const { DocumentTypes, getAutomationParams } = require("../../../db/utils") const { DocumentTypes, getAutomationParams } = require("../../../db/utils")
@ -97,7 +97,7 @@ async function deployApp(deployment) {
try { try {
const appId = getAppId() const appId = getAppId()
const devAppId = getDevelopmentAppID(appId) const devAppId = getDevelopmentAppID(appId)
const productionAppId = getDeployedAppID(appId) const productionAppId = getProdAppID(appId)
const replication = new Replication({ const replication = new Replication({
source: devAppId, source: devAppId,

View File

@ -3,7 +3,7 @@ const env = require("../../environment")
const { checkSlashesInUrl } = require("../../utilities") const { checkSlashesInUrl } = require("../../utilities")
const { request } = require("../../utilities/workerRequests") const { request } = require("../../utilities/workerRequests")
const { clearLock } = require("../../utilities/redis") 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 { DocumentTypes } = require("../../db/utils")
const { app: appCache } = require("@budibase/backend-core/cache") const { app: appCache } = require("@budibase/backend-core/cache")
const { getProdAppDB, getAppDB } = require("@budibase/backend-core/context") const { getProdAppDB, getAppDB } = require("@budibase/backend-core/context")
@ -77,7 +77,7 @@ exports.clearLock = async ctx => {
exports.revert = async ctx => { exports.revert = async ctx => {
const { appId } = ctx.params const { appId } = ctx.params
const productionAppId = getDeployedAppID(appId) const productionAppId = getProdAppID(appId)
// App must have been deployed first // App must have been deployed first
try { try {

View File

@ -10,7 +10,7 @@ const { isEqual } = require("lodash")
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
const { const {
getDevelopmentAppID, getDevelopmentAppID,
getDeployedAppIDs, getProdAppIDs,
dbExists, dbExists,
} = require("@budibase/backend-core/db") } = require("@budibase/backend-core/db")
const { UserStatus } = require("@budibase/backend-core/constants") const { UserStatus } = require("@budibase/backend-core/constants")
@ -92,7 +92,7 @@ exports.syncUser = async function (ctx) {
let prodAppIds let prodAppIds
// if they are a builder then get all production app IDs // if they are a builder then get all production app IDs
if ((user.builder && user.builder.global) || deleting) { if ((user.builder && user.builder.global) || deleting) {
prodAppIds = await getDeployedAppIDs() prodAppIds = await getProdAppIDs()
} else { } else {
prodAppIds = Object.entries(roles) prodAppIds = Object.entries(roles)
.filter(entry => entry[1] !== BUILTIN_ROLE_IDS.PUBLIC) .filter(entry => entry[1] !== BUILTIN_ROLE_IDS.PUBLIC)

View File

@ -2,7 +2,7 @@ const { generateWebhookID, getWebhookParams } = require("../../db/utils")
const toJsonSchema = require("to-json-schema") const toJsonSchema = require("to-json-schema")
const validate = require("jsonschema").validate const validate = require("jsonschema").validate
const triggers = require("../../automations/triggers") 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 { getAppDB, updateAppId } = require("@budibase/backend-core/context")
const AUTOMATION_DESCRIPTION = "Generated from Webhook Schema" const AUTOMATION_DESCRIPTION = "Generated from Webhook Schema"
@ -82,8 +82,8 @@ exports.buildSchema = async ctx => {
} }
exports.trigger = async ctx => { exports.trigger = async ctx => {
const deployedAppId = getDeployedAppID(ctx.params.instance) const prodAppId = getProdAppID(ctx.params.instance)
updateAppId(deployedAppId) updateAppId(prodAppId)
try { try {
const db = getAppDB() const db = getAppDB()
const webhook = await db.get(ctx.params.id) const webhook = await db.get(ctx.params.id)
@ -98,7 +98,7 @@ exports.trigger = async ctx => {
await triggers.externalTrigger(target, { await triggers.externalTrigger(target, {
body: ctx.request.body, body: ctx.request.body,
...ctx.request.body, ...ctx.request.body,
appId: deployedAppId, appId: prodAppId,
}) })
} }
ctx.status = 200 ctx.status = 200

View File

@ -6,7 +6,7 @@ const { queue } = require("./bullboard")
const newid = require("../db/newid") const newid = require("../db/newid")
const { updateEntityMetadata } = require("../utilities") const { updateEntityMetadata } = require("../utilities")
const { MetadataTypes } = require("../constants") const { MetadataTypes } = require("../constants")
const { getDeployedAppID } = require("@budibase/backend-core/db") const { getProdAppID } = require("@budibase/backend-core/db")
const { cloneDeep } = require("lodash/fp") const { cloneDeep } = require("lodash/fp")
const { getAppDB, getAppId } = require("@budibase/backend-core/context") 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 // the app ID has to be development for this endpoint
// it can only be used when building the app // it can only be used when building the app
// but the trigger endpoint will always be used in production // but the trigger endpoint will always be used in production
const prodAppId = getDeployedAppID(appId) const prodAppId = getProdAppID(appId)
newTrigger.inputs = { newTrigger.inputs = {
schemaUrl: `api/webhooks/schema/${appId}/${id}`, schemaUrl: `api/webhooks/schema/${appId}/${id}`,
triggerUrl: `api/webhooks/trigger/${prodAppId}/${id}`, triggerUrl: `api/webhooks/trigger/${prodAppId}/${id}`,

View File

@ -3,7 +3,7 @@ const {
getGlobalIDFromUserMetadataID, getGlobalIDFromUserMetadataID,
} = require("../db/utils") } = require("../db/utils")
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") 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 { getGlobalUserParams } = require("@budibase/backend-core/db")
const { user: userCache } = require("@budibase/backend-core/cache") const { user: userCache } = require("@budibase/backend-core/cache")
const { const {
@ -26,7 +26,7 @@ exports.updateAppRole = (user, { appId } = {}) => {
return user return user
} }
// always use the deployed app // 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 a role wasn't found then either set as admin (builder) or public (everyone else)
if (!user.roleId && user.builder && user.builder.global) { if (!user.roleId && user.builder && user.builder.global) {
user.roleId = BUILTIN_ROLE_IDS.ADMIN user.roleId = BUILTIN_ROLE_IDS.ADMIN

View File

@ -7,7 +7,7 @@ const { deleteFiles } = require("../../utilities/fileSystem/utilities")
const { ObjectStoreBuckets } = require("../../constants") const { ObjectStoreBuckets } = require("../../constants")
const { const {
isProdAppID, isProdAppID,
getDeployedAppID, getProdAppID,
dbExists, dbExists,
} = require("@budibase/backend-core/db") } = require("@budibase/backend-core/db")
const { getAppId } = require("@budibase/backend-core/context") 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 }) => { exports.cleanupAttachments = async (table, { row, rows, oldRow, oldTable }) => {
const appId = getAppId() const appId = getAppId()
if (!isProdAppID(appId)) { if (!isProdAppID(appId)) {
const prodAppId = getDeployedAppID(appId) const prodAppId = getProdAppID(appId)
// if prod exists, then don't allow deleting // if prod exists, then don't allow deleting
const exists = await dbExists(prodAppId) const exists = await dbExists(prodAppId)
if (exists) { if (exists) {

View File

@ -1,7 +1,7 @@
const fetch = require("node-fetch") const fetch = require("node-fetch")
const env = require("../environment") const env = require("../environment")
const { checkSlashesInUrl } = require("./index") const { checkSlashesInUrl } = require("./index")
const { getDeployedAppID } = require("@budibase/backend-core/db") const { getProdAppID } = require("@budibase/backend-core/db")
const { updateAppRole } = require("./global") const { updateAppRole } = require("./global")
const { Headers } = require("@budibase/backend-core/constants") const { Headers } = require("@budibase/backend-core/constants")
const { getTenantId, isTenantIdSet } = require("@budibase/backend-core/tenancy") const { getTenantId, isTenantIdSet } = require("@budibase/backend-core/tenancy")
@ -76,9 +76,9 @@ exports.getGlobalSelf = async (ctx, appId = null) => {
} }
exports.removeAppFromUserRoles = async (ctx, appId) => { exports.removeAppFromUserRoles = async (ctx, appId) => {
const deployedAppId = getDeployedAppID(appId) const prodAppId = getProdAppID(appId)
const response = await fetch( const response = await fetch(
checkSlashesInUrl(env.WORKER_URL + `/api/global/roles/${deployedAppId}`), checkSlashesInUrl(env.WORKER_URL + `/api/global/roles/${prodAppId}`),
request(ctx, { request(ctx, {
method: "DELETE", method: "DELETE",
}) })

View File

@ -1,7 +1,7 @@
const { getAllRoles } = require("@budibase/backend-core/roles") const { getAllRoles } = require("@budibase/backend-core/roles")
const { const {
getAllApps, getAllApps,
getDeployedAppID, getProdAppID,
DocumentTypes, DocumentTypes,
} = require("@budibase/backend-core/db") } = require("@budibase/backend-core/db")
const { doInAppContext, getAppDB } = require("@budibase/backend-core/context") const { doInAppContext, getAppDB } = require("@budibase/backend-core/context")
@ -18,7 +18,7 @@ exports.fetch = async ctx => {
const roles = await Promise.all(promises) const roles = await Promise.all(promises)
const response = {} const response = {}
for (let app of apps) { for (let app of apps) {
const deployedAppId = getDeployedAppID(app.appId) const deployedAppId = getProdAppID(app.appId)
response[deployedAppId] = { response[deployedAppId] = {
roles: roles.shift(), roles: roles.shift(),
name: app.name, name: app.name,