From 573efea5b56fc6badc2000d0a38a6ef64c03aaa6 Mon Sep 17 00:00:00 2001 From: Marko Djordjevic Date: Mon, 16 Feb 2026 19:43:32 +0100 Subject: [PATCH] fix: improve migration error handling to gracefully handle existing tables --- src/lib/db/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/db/index.ts b/src/lib/db/index.ts index 4a4400d..3a5dbfe 100644 --- a/src/lib/db/index.ts +++ b/src/lib/db/index.ts @@ -24,10 +24,12 @@ if (!isBuildTime) { migrate(db, { migrationsFolder: path.join(process.cwd(), 'drizzle') }); console.log('✅ Database migrations completed'); } catch (error) { - // Check if error is about table already existing + // Check if error is about table already existing - this is expected when container restarts with existing volume const errorMessage = error instanceof Error ? error.message : String(error); - if (errorMessage.includes('already exists')) { - console.log('⚠️ Database tables already exist, skipping migrations'); + const causeMessage = error instanceof Error && error.cause ? String(error.cause) : ''; + + if (errorMessage.includes('already exists') || causeMessage.includes('already exists')) { + console.log('ℹ️ Database schema already up to date'); } else { console.error('❌ Migration failed:', error); throw error;