From 414ae577f1382a7ebc5f196e5a7a8a1835f1a51f Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Mon, 3 Mar 2025 21:42:43 -0800 Subject: [PATCH] Support running two JIT migrations in one query --- src/photo/db/query.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/photo/db/query.ts b/src/photo/db/query.ts index e1d2d7fb..755b4798 100644 --- a/src/photo/db/query.ts +++ b/src/photo/db/query.ts @@ -77,12 +77,25 @@ const safelyQueryPhotos = async ( try { result = await callback(); } catch (e: any) { - const migration = migrationForError(e); + let migration = migrationForError(e); console.log('Query error', e); if (migration) { console.log(`Running Migration ${migration.label} ...`); await migration.run(); - result = await callback(); + try { + result = await callback(); + } catch (e: any) { + // Catch potential second migration, + // which otherwise would not be caught + 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)) { // If the table does not exist, create it console.log('Creating photos table ...');