Skip to content

Commit

Permalink
Use public URL for waking up
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelblaszczyk5 committed Jan 4, 2024
1 parent 82b6f12 commit 1e2299c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions prisma/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit 1e2299c

Please sign in to comment.