From df452d849decc8156d9b3a2bf29064641fe50431 Mon Sep 17 00:00:00 2001 From: sai80082 Date: Thu, 5 Feb 2026 15:49:02 +0530 Subject: [PATCH] fix: DB schema update to support latest immich release --- src/pages/api/albums/[id]/assets.ts | 5 ++--- src/pages/api/albums/[id]/info.ts | 4 ++-- src/pages/api/albums/[id]/people.ts | 4 ++-- src/pages/api/albums/[id]/public-info.ts | 4 ++-- src/pages/api/albums/list.ts | 4 ++-- src/pages/api/albums/merge.ts | 4 ++-- src/pages/api/albums/potential-albums-assets.ts | 1 - src/pages/api/albums/potential-albums-dates.ts | 4 ++-- src/pages/api/assets/empty-videos.ts | 1 - src/pages/api/assets/geo-heatmap.ts | 6 +++--- src/pages/api/assets/missing-location-albums.ts | 4 ++-- src/pages/api/assets/missing-location-assets.ts | 6 ++---- src/pages/api/people/[id]/info.ts | 4 ++-- src/pages/api/rewind/stats.ts | 4 ++-- src/pages/api/share-link/[token]/assets.ts | 5 ++--- src/pages/api/share-link/[token]/people.ts | 4 ++-- src/schema/albumAssetsAssets.schema.ts | 4 ++-- src/schema/assets.schema.ts | 1 - src/schema/relationships.ts | 4 ++-- 19 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/pages/api/albums/[id]/assets.ts b/src/pages/api/albums/[id]/assets.ts index 78e5b2e..329fca4 100644 --- a/src/pages/api/albums/[id]/assets.ts +++ b/src/pages/api/albums/[id]/assets.ts @@ -36,7 +36,6 @@ export default async function handler( duration: assets.duration, encodedVideoPath: assets.encodedVideoPath, originalFileName: assets.originalFileName, - sidecarPath: assets.sidecarPath, deletedAt: assets.deletedAt, localDateTime: assets.localDateTime, exifImageWidth: exif.exifImageWidth, @@ -46,12 +45,12 @@ export default async function handler( orientation: exif.orientation, }) .from(albumsAssetsAssets) - .leftJoin(assets, eq(albumsAssetsAssets.assetsId, assets.id)) + .leftJoin(assets, eq(albumsAssetsAssets.assetId, assets.id)) .leftJoin(exif, eq(assets.id, exif.assetId)) .leftJoin(assetFaces, eq(assets.id, assetFaces.assetId)) .leftJoin(person, eq(assetFaces.personId, person.id)) .where(and( - eq(albumsAssetsAssets.albumsId, id), + eq(albumsAssetsAssets.albumId, id), eq(assets.visibility, "timeline"), eq(assets.status, "active"), faceId ? eq(assetFaces.personId, faceId) : undefined, diff --git a/src/pages/api/albums/[id]/info.ts b/src/pages/api/albums/[id]/info.ts index 8b20d42..e0fb466 100644 --- a/src/pages/api/albums/[id]/info.ts +++ b/src/pages/api/albums/[id]/info.ts @@ -31,8 +31,8 @@ export default async function handler( faceCount: count(sql`DISTINCT ${person.id}`), // Ensure unique personId }) .from(albums) - .leftJoin(albumsAssetsAssets, eq(albums.id, albumsAssetsAssets.albumsId)) - .leftJoin(assets, eq(albumsAssetsAssets.assetsId, assets.id)) + .leftJoin(albumsAssetsAssets, eq(albums.id, albumsAssetsAssets.albumId)) + .leftJoin(assets, eq(albumsAssetsAssets.assetId, assets.id)) .leftJoin(exif, and(eq(assets.id, exif.assetId), eq(assets.visibility, "timeline"))) .leftJoin(assetFaces, eq(assets.id, assetFaces.assetId)) .leftJoin(person, and(eq(assetFaces.personId, person.id), eq(person.isHidden, false))) diff --git a/src/pages/api/albums/[id]/people.ts b/src/pages/api/albums/[id]/people.ts index 81f3b3c..b39c3db 100644 --- a/src/pages/api/albums/[id]/people.ts +++ b/src/pages/api/albums/[id]/people.ts @@ -26,8 +26,8 @@ export default async function handler( numberOfPhotos: count(assets.id), }) .from(albums) - .leftJoin(albumsAssetsAssets, eq(albums.id, albumsAssetsAssets.albumsId)) - .leftJoin(assets, eq(albumsAssetsAssets.assetsId, assets.id)) + .leftJoin(albumsAssetsAssets, eq(albums.id, albumsAssetsAssets.albumId)) + .leftJoin(assets, eq(albumsAssetsAssets.assetId, assets.id)) .leftJoin(assetFaces, eq(assets.id, assetFaces.assetId)) .leftJoin(person, and(eq(assetFaces.personId, person.id), eq(person.isHidden, false))) .where(and(eq(albums.ownerId, currentUser.id), eq(albums.id, id), isNotNull(person.id))) diff --git a/src/pages/api/albums/[id]/public-info.ts b/src/pages/api/albums/[id]/public-info.ts index b844192..5296144 100644 --- a/src/pages/api/albums/[id]/public-info.ts +++ b/src/pages/api/albums/[id]/public-info.ts @@ -27,8 +27,8 @@ export default async function handler( faceCount: count(sql`DISTINCT ${person.id}`), // Ensure unique personId }) .from(albums) - .leftJoin(albumsAssetsAssets, eq(albums.id, albumsAssetsAssets.albumsId)) - .leftJoin(assets, eq(albumsAssetsAssets.assetsId, assets.id)) + .leftJoin(albumsAssetsAssets, eq(albums.id, albumsAssetsAssets.albumId)) + .leftJoin(assets, eq(albumsAssetsAssets.assetId, assets.id)) .leftJoin(exif, and(eq(assets.id, exif.assetId), eq(assets.visibility, "timeline"))) .leftJoin(assetFaces, eq(assets.id, assetFaces.assetId)) .leftJoin(person, and(eq(assetFaces.personId, person.id), eq(person.isHidden, false))) diff --git a/src/pages/api/albums/list.ts b/src/pages/api/albums/list.ts index 97df105..4eb2f17 100644 --- a/src/pages/api/albums/list.ts +++ b/src/pages/api/albums/list.ts @@ -69,9 +69,9 @@ export default async function handler( faceCount: count(sql`DISTINCT ${assetFaces.personId}`), // Ensure unique personId }) .from(albums) - .leftJoin(albumsAssetsAssets, eq(albums.id, albumsAssetsAssets.albumsId)) + .leftJoin(albumsAssetsAssets, eq(albums.id, albumsAssetsAssets.albumId)) .leftJoin(assets, and( - eq(albumsAssetsAssets.assetsId, assets.id), + eq(albumsAssetsAssets.assetId, assets.id), eq(assets.visibility, "timeline"), eq(assets.status, "active"), )) diff --git a/src/pages/api/albums/merge.ts b/src/pages/api/albums/merge.ts index b10e873..45e56ab 100644 --- a/src/pages/api/albums/merge.ts +++ b/src/pages/api/albums/merge.ts @@ -61,13 +61,13 @@ export default async function handler( const secondaryAlbumAssets = await db .select() .from(albumsAssetsAssets) - .where(inArray(albumsAssetsAssets.albumsId, secondaryAlbumIds)); + .where(inArray(albumsAssetsAssets.albumId, secondaryAlbumIds)); if (secondaryAlbumAssets.length === 0) { return res.status(404).json({ error: "Secondary album assets not found" }); } - const secondaryAlbumAssetsIds = secondaryAlbumAssets.map((albumAsset) => albumAsset.assetsId); + const secondaryAlbumAssetsIds = secondaryAlbumAssets.map((albumAsset) => albumAsset.assetId); const addAssetsToPrimaryAlbumURL = `${ENV.IMMICH_URL}/api/albums/${primaryAlbumId}/assets`; const addAssetsToPrimaryAlbum = await fetch(addAssetsToPrimaryAlbumURL, { diff --git a/src/pages/api/albums/potential-albums-assets.ts b/src/pages/api/albums/potential-albums-assets.ts index 01558a2..6ac09d2 100644 --- a/src/pages/api/albums/potential-albums-assets.ts +++ b/src/pages/api/albums/potential-albums-assets.ts @@ -16,7 +16,6 @@ const SELECT_ORPHAN_PHOTOS = (date: string, ownerId: string) => a."duration", a."encodedVideoPath", a."originalFileName", - a."sidecarPath", a."thumbhash", a."deletedAt", e."exifImageWidth", diff --git a/src/pages/api/albums/potential-albums-dates.ts b/src/pages/api/albums/potential-albums-dates.ts index 47a5c25..e9670aa 100644 --- a/src/pages/api/albums/potential-albums-dates.ts +++ b/src/pages/api/albums/potential-albums-dates.ts @@ -21,12 +21,12 @@ export default async function handler( date: sql`DATE(${exif.dateTimeOriginal})`, asset_count: desc(count(assets.id)), }).from(assets) - .leftJoin(albumsAssetsAssets, eq(assets.id, albumsAssetsAssets.assetsId)) + .leftJoin(albumsAssetsAssets, eq(assets.id, albumsAssetsAssets.assetId)) .leftJoin(exif, eq(assets.id, exif.assetId)) .where(and ( eq(assets.ownerId, currentUser.id), eq(assets.visibility, "timeline"), - isNull(albumsAssetsAssets.albumsId), + isNull(albumsAssetsAssets.albumId), isNotNull(exif.dateTimeOriginal), )) diff --git a/src/pages/api/assets/empty-videos.ts b/src/pages/api/assets/empty-videos.ts index e97d877..5b2bdf4 100644 --- a/src/pages/api/assets/empty-videos.ts +++ b/src/pages/api/assets/empty-videos.ts @@ -58,7 +58,6 @@ const dbAssets = await db duration: assets.duration, encodedVideoPath: assets.encodedVideoPath, originalFileName: assets.originalFileName, - sidecarPath: assets.sidecarPath, deletedAt: assets.deletedAt, localDateTime: assets.localDateTime, exifImageWidth: exif.exifImageWidth, diff --git a/src/pages/api/assets/geo-heatmap.ts b/src/pages/api/assets/geo-heatmap.ts index e3d6eb0..b48f216 100644 --- a/src/pages/api/assets/geo-heatmap.ts +++ b/src/pages/api/assets/geo-heatmap.ts @@ -21,15 +21,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) longitude: exif.longitude, }).from(assets) .innerJoin(exif, eq(assets.id, exif.assetId)) - .innerJoin(albumsAssetsAssets, eq(assets.id, albumsAssetsAssets.assetsId)) - .innerJoin(assetFaces, eq(albumsAssetsAssets.assetsId, assetFaces.assetId)) + .innerJoin(albumsAssetsAssets, eq(assets.id, albumsAssetsAssets.assetId)) + .innerJoin(assetFaces, eq(albumsAssetsAssets.assetId, assetFaces.assetId)) .innerJoin(person, eq(assetFaces.personId, person.id)) .where( and( eq(assets.ownerId, currentUser.id), isNotNull(exif.latitude), isNotNull(exif.longitude), - albumIds?.length > 0 ? inArray(albumsAssetsAssets.albumsId, [albumIds]) : undefined, + albumIds?.length > 0 ? inArray(albumsAssetsAssets.albumId, [albumIds]) : undefined, peopleIds?.length > 0 ? inArray(person.id, [peopleIds]) : undefined ) ); diff --git a/src/pages/api/assets/missing-location-albums.ts b/src/pages/api/assets/missing-location-albums.ts index 4bca99e..69d183e 100644 --- a/src/pages/api/assets/missing-location-albums.ts +++ b/src/pages/api/assets/missing-location-albums.ts @@ -27,8 +27,8 @@ export default async function handler( }) .from(assets) .leftJoin(exif, eq(exif.assetId, assets.id)) - .leftJoin(albumsAssetsAssets, eq(albumsAssetsAssets.assetsId, assets.id)) - .leftJoin(albums, eq(albums.id, albumsAssetsAssets.albumsId)) + .leftJoin(albumsAssetsAssets, eq(albumsAssetsAssets.assetId, assets.id)) + .leftJoin(albums, eq(albums.id, albumsAssetsAssets.albumId)) .where( and( isNull(exif.latitude), diff --git a/src/pages/api/assets/missing-location-assets.ts b/src/pages/api/assets/missing-location-assets.ts index 66a5d0e..3355ca9 100644 --- a/src/pages/api/assets/missing-location-assets.ts +++ b/src/pages/api/assets/missing-location-assets.ts @@ -22,7 +22,6 @@ const getRowsByDates = async (startDateDate: Date, endDateDate: Date, currentUse duration: assets.duration, encodedVideoPath: assets.encodedVideoPath, originalFileName: assets.originalFileName, - sidecarPath: assets.sidecarPath, deletedAt: assets.deletedAt, localDateTime: assets.localDateTime, exifImageWidth: exif.exifImageWidth, @@ -55,7 +54,6 @@ const getRowsByAlbums = async (currentUser: IUser, albumId: string) => { duration: assets.duration, encodedVideoPath: assets.encodedVideoPath, originalFileName: assets.originalFileName, - sidecarPath: assets.sidecarPath, deletedAt: assets.deletedAt, localDateTime: assets.localDateTime, exifImageWidth: exif.exifImageWidth, @@ -66,8 +64,8 @@ const getRowsByAlbums = async (currentUser: IUser, albumId: string) => { }) .from(assets) .leftJoin(exif, eq(exif.assetId, assets.id)) - .leftJoin(albumsAssetsAssets, eq(albumsAssetsAssets.assetsId, assets.id)) - .leftJoin(albums, eq(albums.id, albumsAssetsAssets.albumsId)) + .leftJoin(albumsAssetsAssets, eq(albumsAssetsAssets.assetId, assets.id)) + .leftJoin(albums, eq(albums.id, albumsAssetsAssets.albumId)) .where(and( isNull(exif.latitude), isNotNull(assets.createdAt), diff --git a/src/pages/api/people/[id]/info.ts b/src/pages/api/people/[id]/info.ts index 1961149..1f26f24 100644 --- a/src/pages/api/people/[id]/info.ts +++ b/src/pages/api/people/[id]/info.ts @@ -36,8 +36,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) .leftJoin(assetFaces, eq(assetFaces.personId, personRecord.id)) .leftJoin(assets, eq(assets.id, assetFaces.assetId)) .leftJoin(exif, eq(exif.assetId, assets.id)) - .leftJoin(albumsAssetsAssets, eq(albumsAssetsAssets.assetsId, assets.id)) - .where(eq(albumsAssetsAssets.albumsId, albums.id)) + .leftJoin(albumsAssetsAssets, eq(albumsAssetsAssets.assetId, assets.id)) + .where(eq(albumsAssetsAssets.albumId, albums.id)) .groupBy(albums.id); diff --git a/src/pages/api/rewind/stats.ts b/src/pages/api/rewind/stats.ts index d8dc1fb..3824478 100644 --- a/src/pages/api/rewind/stats.ts +++ b/src/pages/api/rewind/stats.ts @@ -66,8 +66,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) cover: albums.albumThumbnailAssetId }) .from(albumsAssetsAssets) - .leftJoin(albums, eq(albums.id, albumsAssetsAssets.albumsId)) - .leftJoin(assets, eq(assets.id, albumsAssetsAssets.assetsId)) + .leftJoin(albums, eq(albums.id, albumsAssetsAssets.albumId)) + .leftJoin(assets, eq(assets.id, albumsAssetsAssets.assetId)) .leftJoin(exif, eq(exif.assetId, assets.id)) .where(and( eq(sql`EXTRACT(YEAR FROM ${exif.dateTimeOriginal})`, year), diff --git a/src/pages/api/share-link/[token]/assets.ts b/src/pages/api/share-link/[token]/assets.ts index 635a8fb..6066e46 100644 --- a/src/pages/api/share-link/[token]/assets.ts +++ b/src/pages/api/share-link/[token]/assets.ts @@ -63,7 +63,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) duration: assets.duration, encodedVideoPath: assets.encodedVideoPath, originalFileName: assets.originalFileName, - sidecarPath: assets.sidecarPath, deletedAt: assets.deletedAt, localDateTime: assets.localDateTime, exifImageWidth: exif.exifImageWidth, @@ -76,8 +75,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) orientation: exif.orientation, }).from(assets) .innerJoin(assetFaces, eq(assets.id, assetFaces.assetId)) - .leftJoin(albumsAssetsAssets, eq(assets.id, albumsAssetsAssets.assetsId)) - .leftJoin(albums, eq(albumsAssetsAssets.albumsId, albums.id)) + .leftJoin(albumsAssetsAssets, eq(assets.id, albumsAssetsAssets.assetId)) + .leftJoin(albums, eq(albumsAssetsAssets.albumId, albums.id)) .innerJoin(exif, eq(exif.assetId, assets.id)) .where(and( filteredPersonIds?.length > 0 ? inArray(assetFaces.personId, filteredPersonIds) : undefined, diff --git a/src/pages/api/share-link/[token]/people.ts b/src/pages/api/share-link/[token]/people.ts index 694ee65..02449f3 100644 --- a/src/pages/api/share-link/[token]/people.ts +++ b/src/pages/api/share-link/[token]/people.ts @@ -44,9 +44,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) assetCount: count(assets.id), }).from(assets) .innerJoin(assetFaces, eq(assets.id, assetFaces.assetId)) - .innerJoin(albumsAssetsAssets, eq(assets.id, albumsAssetsAssets.assetsId)) + .innerJoin(albumsAssetsAssets, eq(assets.id, albumsAssetsAssets.assetId)) .innerJoin(person, eq(assetFaces.personId, person.id)) - .innerJoin(albums, eq(albumsAssetsAssets.albumsId, albums.id)) + .innerJoin(albums, eq(albumsAssetsAssets.albumId, albums.id)) .innerJoin(exif, eq(exif.assetId, assets.id)) .where(and( personIds?.length > 0 ? inArray(assetFaces.personId, personIds) : undefined, diff --git a/src/schema/albumAssetsAssets.schema.ts b/src/schema/albumAssetsAssets.schema.ts index 4aabfd5..ee0ae1f 100644 --- a/src/schema/albumAssetsAssets.schema.ts +++ b/src/schema/albumAssetsAssets.schema.ts @@ -1,7 +1,7 @@ import { pgTable, uuid, timestamp } from 'drizzle-orm/pg-core'; export const albumsAssetsAssets = pgTable('album_asset', { - albumsId: uuid('albumId').notNull(), - assetsId: uuid('assetId').notNull(), + albumId: uuid('albumId').notNull(), + assetId: uuid('assetId').notNull(), createdAt: timestamp('createdAt', { withTimezone: true }).defaultNow().notNull(), }); \ No newline at end of file diff --git a/src/schema/assets.schema.ts b/src/schema/assets.schema.ts index 0f9b564..7782143 100644 --- a/src/schema/assets.schema.ts +++ b/src/schema/assets.schema.ts @@ -19,7 +19,6 @@ export const assets = pgTable('asset', { createdAt: timestamp('createdAt', { withTimezone: true }).defaultNow().notNull(), status: varchar('status').default('active').notNull(), originalFileName: varchar('originalFileName').notNull(), - sidecarPath: varchar('sidecarPath'), // thumbhash: bytea('thumbhash'), isOffline: boolean('isOffline').default(false).notNull(), // libraryId: uuid('libraryId').references(() => libraries.id, { onDelete: 'cascade', onUpdate: 'cascade' }), diff --git a/src/schema/relationships.ts b/src/schema/relationships.ts index 4b5d15b..303c359 100644 --- a/src/schema/relationships.ts +++ b/src/schema/relationships.ts @@ -44,11 +44,11 @@ export const faceSearchRelations = relations(faceSearch, ({ one }) => ({ // Assuming there are relations to be defined with `albums` and `assets` export const albumsAssetsAssetsRelations = relations(albumsAssetsAssets, ({ one }) => ({ album: one(albums, { - fields: [albumsAssetsAssets.albumsId], + fields: [albumsAssetsAssets.albumId], references: [albums.id], }), asset: one(assets, { - fields: [albumsAssetsAssets.assetsId], + fields: [albumsAssetsAssets.assetId], references: [assets.id], }), }));