From a4382af9bec61863cf8077bb7661d6992dc1aa48 Mon Sep 17 00:00:00 2001 From: Rolf Date: Wed, 18 Mar 2026 14:35:27 +0100 Subject: [PATCH] fixed some routing issues --- instrumentation.ts | 21 ++++++++++++++++----- lib/db/index.ts | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/instrumentation.ts b/instrumentation.ts index 6759892..66a7620 100644 --- a/instrumentation.ts +++ b/instrumentation.ts @@ -1,4 +1,5 @@ export async function register() { + console.log('[instrumentation] register() called, NEXT_RUNTIME =', process.env.NEXT_RUNTIME) if (process.env.NEXT_RUNTIME === 'nodejs') { const fs = await import('fs') const path = await import('path') @@ -9,10 +10,20 @@ export async function register() { return } - console.log('[migrations] Applying migrations from', path.dirname(journal)) - const { migrate } = await import('drizzle-orm/postgres-js/migrator') - const { db } = await import('@/lib/db') - await migrate(db, { migrationsFolder: './lib/db/migrations' }) - console.log('[migrations] Done') + console.log('[migrations] Applying migrations...') + try { + const postgres = (await import('postgres')).default + const { drizzle } = await import('drizzle-orm/postgres-js') + const { migrate } = await import('drizzle-orm/postgres-js/migrator') + + // Dedicated single connection for migrations — never share with the app pool + const client = postgres(process.env.DATABASE_URL!, { max: 1, connect_timeout: 10 }) + const db = drizzle(client) + await migrate(db, { migrationsFolder: './lib/db/migrations' }) + await client.end() + console.log('[migrations] Done') + } catch (err) { + console.error('[migrations] Failed:', err) + } } } diff --git a/lib/db/index.ts b/lib/db/index.ts index 6575765..30818f0 100644 --- a/lib/db/index.ts +++ b/lib/db/index.ts @@ -2,5 +2,5 @@ import { drizzle } from 'drizzle-orm/postgres-js' import postgres from 'postgres' import * as schema from './schema' -const client = postgres(process.env.DATABASE_URL!) +const client = postgres(process.env.DATABASE_URL!, { connect_timeout: 10 }) export const db = drizzle(client, { schema, logger: true })