From 9787f791767c08baaba057bd132099440d720bec Mon Sep 17 00:00:00 2001 From: 4gray Date: Tue, 3 Mar 2026 12:03:01 +0100 Subject: [PATCH] fix(database): silence expected duplicate-column migration logs --- libs/shared/database/src/lib/connection.ts | 28 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/libs/shared/database/src/lib/connection.ts b/libs/shared/database/src/lib/connection.ts index 09e6906a3..95e91292d 100644 --- a/libs/shared/database/src/lib/connection.ts +++ b/libs/shared/database/src/lib/connection.ts @@ -242,6 +242,15 @@ function createTables(sqliteDb: Database.Database): void { } } +function isDuplicateColumnError(error: unknown): boolean { + const message = + typeof error === 'object' && error !== null && 'message' in error + ? String((error as { message?: unknown }).message ?? '') + : ''; + + return message.toLowerCase().includes('duplicate column name'); +} + /** * Run migrations that may fail if already applied */ @@ -250,9 +259,22 @@ function runMigrations(sqliteDb: Database.Database): void { try { sqliteDb.exec(stmt); } catch (error) { - // Log and ignore errors for migrations that may have already been applied - // (e.g., "duplicate column name" for ALTER TABLE ADD COLUMN) - console.debug('Migration already applied or failed:', error); + // Ignore idempotent ALTER TABLE errors on existing columns. + if (isDuplicateColumnError(error)) { + continue; + } + + const compactStmt = stmt.replace(/\s+/g, ' ').trim(); + const message = + typeof error === 'object' && + error !== null && + 'message' in error + ? String((error as { message?: unknown }).message ?? error) + : String(error); + + console.warn( + `Migration failed (continuing): ${compactStmt} :: ${message}` + ); } } }