From 09d7a07722f2932ce52b8fcf484f61928c408eb6 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sun, 30 Mar 2025 20:08:49 -0500 Subject: [PATCH] Catch up to 3 JIT migrations --- src/photo/db/query.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/photo/db/query.ts b/src/photo/db/query.ts index 9af7bf0c..d6f5ad0f 100644 --- a/src/photo/db/query.ts +++ b/src/photo/db/query.ts @@ -65,7 +65,8 @@ const createPhotosTable = () => ) `; -// Wrapper for most queries for JIT table creation/migration running +// Safe wrapper for most queries with JIT table creation/migration +// Catch up to 3 migrations in older installations const safelyQueryPhotos = async ( callback: () => Promise, debugMessage: string, @@ -78,6 +79,7 @@ const safelyQueryPhotos = async ( try { result = await callback(); } catch (e: any) { + // Catch 1st migration let migration = migrationForError(e); if (migration) { console.log(`Running Migration ${migration.label} ...`); @@ -85,15 +87,26 @@ const safelyQueryPhotos = async ( try { result = await callback(); } catch (e: any) { - // Catch potential second migration, - // which otherwise would not be caught + // Catch 2nd migration migration = migrationForError(e); if (migration) { console.log(`Running Migration ${migration.label} ...`); await migration.run(); result = await callback(); } else { - throw e; + try { + result = await callback(); + } catch (e: any) { + // Catch 3rd migration + migration = migrationForError(e); + if (migration) { + console.log(`Running Migration ${migration.label} ...`); + await migration.run(); + result = await callback(); + } else { + throw e; + } + } } } } else if (/relation "photos" does not exist/i.test(e.message)) {