From 2cf220133f8738ee5d4c045e4edd25122648e8d3 Mon Sep 17 00:00:00 2001 From: admin-valentin Date: Sat, 1 Aug 2026 20:20:25 +0000 Subject: [PATCH] fix(migration): catch already-exists errors when schema pre-initialized via drizzle push --- src/main.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 4f38214..798a20c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -28,8 +28,17 @@ function validateEnv(): void { async function bootstrap() { validateEnv(); - // Apply pending DB migrations before accepting traffic - await migrate(db, { migrationsFolder: './drizzle' }); + // Apply pending DB migrations — skip if schema was pre-initialized via drizzle push + try { + await migrate(db, { migrationsFolder: './drizzle' }); + } catch (err) { + const msg = (err as Error & { message: string }).message ?? ''; + if (msg.includes('already exists')) { + console.warn('[bootstrap] Schema already initialized — migration skipped. Run db:migrate manually if needed.'); + } else { + throw err; + } + } const app = await NestFactory.create(AppModule, { bufferLogs: true }); app.useLogger(app.get(Logger));