diff --git a/src/photo/db/query.ts b/src/photo/db/query.ts index c6c96d5c..9adfae8f 100644 --- a/src/photo/db/query.ts +++ b/src/photo/db/query.ts @@ -39,6 +39,8 @@ const createPhotosTable = () => model VARCHAR(255), focal_length SMALLINT, focal_length_in_35mm_format SMALLINT, + lens_make VARCHAR(255), + lens_model VARCHAR(255), f_number REAL, iso SMALLINT, exposure_time DOUBLE PRECISION, @@ -65,6 +67,15 @@ const runMigration01 = () => ADD COLUMN IF NOT EXISTS semantic_description TEXT `; +// Migration 02 +const MIGRATION_FIELDS_02 = ['lens_make', 'lens_model']; +const runMigration02 = () => + sql` + ALTER TABLE photos + ADD COLUMN IF NOT EXISTS lens_make VARCHAR(255), + ADD COLUMN IF NOT EXISTS lens_model VARCHAR(255) + `; + // Wrapper for most queries for JIT table creation/migration running const safelyQueryPhotos = async ( callback: () => Promise, @@ -84,6 +95,13 @@ const safelyQueryPhotos = async ( console.log('Running migration 01 ...'); await runMigration01(); result = await callback(); + } else if (MIGRATION_FIELDS_02.some(field => new RegExp( + `column "${field}" of relation "photos" does not exist`, + 'i', + ).test(e.message))) { + console.log('Running migration 02 ...'); + await runMigration02(); + result = await callback(); } else if (/relation "photos" does not exist/i.test(e.message)) { // If the table does not exist, create it console.log('Creating photos table ...'); @@ -131,6 +149,8 @@ export const insertPhoto = (photo: PhotoDbInsert) => model, focal_length, focal_length_in_35mm_format, + lens_make, + lens_model, f_number, iso, exposure_time, @@ -158,6 +178,8 @@ export const insertPhoto = (photo: PhotoDbInsert) => ${photo.model}, ${photo.focalLength}, ${photo.focalLengthIn35MmFormat}, + ${photo.lensMake}, + ${photo.lensModel}, ${photo.fNumber}, ${photo.iso}, ${photo.exposureTime}, @@ -188,6 +210,8 @@ export const updatePhoto = (photo: PhotoDbInsert) => model=${photo.model}, focal_length=${photo.focalLength}, focal_length_in_35mm_format=${photo.focalLengthIn35MmFormat}, + lens_make=${photo.lensMake}, + lens_model=${photo.lensModel}, f_number=${photo.fNumber}, iso=${photo.iso}, exposure_time=${photo.exposureTime}, diff --git a/src/photo/form/index.ts b/src/photo/form/index.ts index da306ab0..fda60105 100644 --- a/src/photo/form/index.ts +++ b/src/photo/form/index.ts @@ -103,6 +103,8 @@ const FORM_METADATA = ( }, focalLength: { label: 'focal length' }, focalLengthIn35MmFormat: { label: 'focal length 35mm-equivalent' }, + lensMake: { label: 'lens make' }, + lensModel: { label: 'lens model' }, fNumber: { label: 'aperture' }, iso: { label: 'ISO' }, exposureTime: { label: 'exposure time' }, @@ -195,6 +197,8 @@ export const convertExifToFormData = ( model: data.tags?.Model, focalLength: data.tags?.FocalLength?.toString(), focalLengthIn35MmFormat: data.tags?.FocalLengthIn35mmFormat?.toString(), + lensMake: data.tags?.LensMake, + lensModel: data.tags?.LensModel, fNumber: data.tags?.FNumber?.toString(), iso: data.tags?.ISO?.toString(), exposureTime: data.tags?.ExposureTime?.toString(), diff --git a/src/photo/index.ts b/src/photo/index.ts index 187de55c..59994e22 100644 --- a/src/photo/index.ts +++ b/src/photo/index.ts @@ -48,6 +48,8 @@ export interface PhotoExif { model?: string focalLength?: number focalLengthIn35MmFormat?: number + lensMake?: string + lensModel?: string fNumber?: number iso?: number exposureTime?: number