Skip to content

Commit

Permalink
Experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelblaszczyk5 committed Jan 4, 2024
1 parent d623355 commit 3ef7339
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions prisma/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable no-console -- These logs are for debugging */

import { PrismaClient } from '@prisma/client';
import { $ } from 'execa';

const MAX_RETRIES = 5;
Expand All @@ -11,7 +14,6 @@ const deployPrismaMigrationsWithRetrying = () => {
try {
const { stdout } = await $`pnpm prisma migrate deploy`;

// eslint-disable-next-line no-console -- this is for debugging in deployment logs
console.log(stdout);
} catch (error) {
if (currentRetry >= MAX_RETRIES) throw error;
Expand All @@ -20,10 +22,15 @@ const deployPrismaMigrationsWithRetrying = () => {

if (!isDatabaseUnavailable) throw error;

try {
await new PrismaClient().$connect();
} catch (error_) {
console.log(error_);
}

const delayMs = BASE_DELAY * 2 ** currentRetry;
currentRetry += 1;

// eslint-disable-next-line no-console -- this is for debugging in deployment logs
console.log(`Retrying migrations #${currentRetry} after ${delayMs}ms`);

await new Promise(resolve => {
Expand Down

0 comments on commit 3ef7339

Please sign in to comment.