fix(migration): catch already-exists errors when schema pre-initialized via drizzle push
This commit is contained in:
parent
54a0c50bbc
commit
2cf220133f
1 changed files with 11 additions and 2 deletions
13
src/main.ts
13
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));
|
||||
|
|
|
|||
Loading…
Reference in a new issue