From b63aa7136610d81b779b400c5fa9f8e87a3a4e71 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Mon, 31 Jan 2022 17:28:45 +0000 Subject: [PATCH] Tolerate missing app metadata in app url migration --- packages/server/src/migrations/functions/appUrls.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/server/src/migrations/functions/appUrls.ts b/packages/server/src/migrations/functions/appUrls.ts index 8852c27822..1446fcafc0 100644 --- a/packages/server/src/migrations/functions/appUrls.ts +++ b/packages/server/src/migrations/functions/appUrls.ts @@ -9,7 +9,16 @@ import { getAppUrl } from "../../api/controllers/application" * Add the url to the app metadata if it doesn't exist */ export const run = async (appDb: any) => { - const metadata = await appDb.get(DocumentTypes.APP_METADATA) + let metadata + try { + metadata = await appDb.get(DocumentTypes.APP_METADATA) + } catch (e) { + // sometimes the metadata document doesn't exist + // exit early instead of failing the migration + console.error("Error retrieving app metadata. Skipping", e) + return + } + if (!metadata.url) { const context = { request: { @@ -20,6 +29,6 @@ export const run = async (appDb: any) => { } metadata.url = getAppUrl(context) console.log(`Adding url to app: ${metadata.url}`) + await appDb.put(metadata) } - await appDb.put(metadata) }