From 090fdb58e00e12353b7fc0347f662bff94b0a9d4 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Wed, 1 Jun 2022 15:17:49 +0100 Subject: [PATCH] app id fixes --- packages/backend-core/src/events/backfill.ts | 3 ++- packages/backend-core/src/migrations/index.js | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/backend-core/src/events/backfill.ts b/packages/backend-core/src/events/backfill.ts index 7b73cc4f82..e4577c5ab4 100644 --- a/packages/backend-core/src/events/backfill.ts +++ b/packages/backend-core/src/events/backfill.ts @@ -18,6 +18,7 @@ import { UserCreatedEvent, RoleAssignedEvent, UserPermissionAssignedEvent, + AppCreatedEvent, } from "@budibase/types" import * as context from "../context" import { CacheKeys } from "../cache/generic" @@ -130,7 +131,7 @@ const CUSTOM_PROPERTY_SUFFIX: any = { [Event.VIEW_FILTER_CREATED]: (properties: ViewFilterCreatedEvent) => { return properties.tableId // best uniqueness }, - [Event.APP_PUBLISHED]: (properties: AppPublishedEvent) => { + [Event.APP_CREATED]: (properties: AppCreatedEvent) => { return properties.appId // best uniqueness }, [Event.APP_PUBLISHED]: (properties: AppPublishedEvent) => { diff --git a/packages/backend-core/src/migrations/index.js b/packages/backend-core/src/migrations/index.js index 6bfedf03c5..11067d4cb0 100644 --- a/packages/backend-core/src/migrations/index.js +++ b/packages/backend-core/src/migrations/index.js @@ -9,6 +9,7 @@ const { getGlobalDBName, getTenantId, } = require("../tenancy") +const context = require("../context") exports.MIGRATION_TYPES = { GLOBAL: "global", // run once per tenant, recorded in global db, global db is provided as an argument @@ -90,7 +91,14 @@ exports.runMigration = async (migration, options = {}) => { `[Tenant: ${tenantId}] [Migration: ${migrationName}] [DB: ${dbName}] Running ${lengthStatement}` ) // run the migration with tenant context - await migration.fn(db) + if (migrationType === exports.MIGRATION_TYPES.APP) { + await context.doInAppContext(db.name, async () => { + await migration.fn(db) + }) + } else { + await migration.fn(db) + } + log( `[Tenant: ${tenantId}] [Migration: ${migrationName}] [DB: ${dbName}] Complete` )