From 1e2299c97e8f1bac5e0de52be186f57596862211 Mon Sep 17 00:00:00 2001 From: pawelblaszczyk5 Date: Thu, 4 Jan 2024 21:06:45 +0100 Subject: [PATCH] Use public URL for waking up --- prisma/deploy.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/prisma/deploy.ts b/prisma/deploy.ts index 9a251f0..2c9dccc 100644 --- a/prisma/deploy.ts +++ b/prisma/deploy.ts @@ -7,6 +7,20 @@ const MAX_RETRIES = 5; const BASE_DELAY = 1_000; +const DATABASE_PUBLIC_URL = process.env['DATABASE_PUBLIC_URL']; + +if (!DATABASE_PUBLIC_URL) { + throw new Error('DATABASE_PUBLIC_URL must be defined for waking up db'); +} + +const tryWakingUpDatabase = async () => { + try { + await new PrismaClient({ datasources: { db: { url: DATABASE_PUBLIC_URL } } }).$connect(); + } catch (error_) { + console.log(error_); + } +}; + const deployPrismaMigrationsWithRetrying = () => { let currentRetry = 0; @@ -22,11 +36,7 @@ const deployPrismaMigrationsWithRetrying = () => { if (!isDatabaseUnavailable) throw error; - try { - await new PrismaClient().$connect(); - } catch (error_) { - console.log(error_); - } + await tryWakingUpDatabase(); const delayMs = BASE_DELAY * 2 ** currentRetry; currentRetry += 1;