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
11
src/main.ts
11
src/main.ts
|
|
@ -28,8 +28,17 @@ function validateEnv(): void {
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
validateEnv();
|
validateEnv();
|
||||||
|
|
||||||
// Apply pending DB migrations before accepting traffic
|
// Apply pending DB migrations — skip if schema was pre-initialized via drizzle push
|
||||||
|
try {
|
||||||
await migrate(db, { migrationsFolder: './drizzle' });
|
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 });
|
const app = await NestFactory.create(AppModule, { bufferLogs: true });
|
||||||
app.useLogger(app.get(Logger));
|
app.useLogger(app.get(Logger));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue