From aa32b1f3722c5bd267dbb6f4b612b5eb9f466389 Mon Sep 17 00:00:00 2001 From: jubnl Date: Tue, 14 Apr 2026 13:39:28 +0200 Subject: [PATCH] fix(migrations): qualify provider column in trip_photos JOIN (migration 98) Both trip_photos (alias tp) and trek_photos (alias tkp) have a provider column. Using the bare identifier 'provider' in the JOIN condition was ambiguous and caused SQLite to throw SQLITE_ERROR, failing migration 98 and taking down the entire test suite setup. Fix: introduce providerJoinExpr = 'tp.provider' when the legacy trip_photos table already carries a provider column, used only in the two-table JOIN. The single-table INSERT keeps the unqualified form. --- server/src/db/migrations.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/src/db/migrations.ts b/server/src/db/migrations.ts index f7076a77..7059391c 100644 --- a/server/src/db/migrations.ts +++ b/server/src/db/migrations.ts @@ -1467,6 +1467,8 @@ function runMigrations(db: Database.Database): void { if (assetCol) { const providerExpr = hasProvider ? 'provider' : "'immich'"; + // Qualified alias needed in JOIN context where both trip_photos and trek_photos have provider + const providerJoinExpr = hasProvider ? 'tp.provider' : "'immich'"; const sharedExpr = tpColNames.has('shared') ? 'shared' : '1'; const addedAtExpr = tpColNames.has('added_at') ? 'COALESCE(added_at, CURRENT_TIMESTAMP)' : 'CURRENT_TIMESTAMP'; const albumLinkExpr = hasAlbumLink ? 'album_link_id' : 'NULL'; @@ -1496,7 +1498,7 @@ function runMigrations(db: Database.Database): void { INSERT OR IGNORE INTO trip_photos_new (trip_id, user_id, photo_id, shared, album_link_id, added_at) SELECT tp.trip_id, tp.user_id, tkp.id, ${sharedExpr}, ${albumLinkExpr}, ${addedAtExpr} FROM trip_photos tp - JOIN trek_photos tkp ON tkp.provider = ${providerExpr} AND tkp.asset_id = tp.${assetCol} AND tkp.owner_id = tp.user_id + JOIN trek_photos tkp ON tkp.provider = ${providerJoinExpr} AND tkp.asset_id = tp.${assetCol} AND tkp.owner_id = tp.user_id `); } else { // No asset column at all — just recreate empty