Add lens make/model to db w/ migrations
This commit is contained in:
parent
668f529ff0
commit
d8d6c68fc8
@ -39,6 +39,8 @@ const createPhotosTable = () =>
|
|||||||
model VARCHAR(255),
|
model VARCHAR(255),
|
||||||
focal_length SMALLINT,
|
focal_length SMALLINT,
|
||||||
focal_length_in_35mm_format SMALLINT,
|
focal_length_in_35mm_format SMALLINT,
|
||||||
|
lens_make VARCHAR(255),
|
||||||
|
lens_model VARCHAR(255),
|
||||||
f_number REAL,
|
f_number REAL,
|
||||||
iso SMALLINT,
|
iso SMALLINT,
|
||||||
exposure_time DOUBLE PRECISION,
|
exposure_time DOUBLE PRECISION,
|
||||||
@ -65,6 +67,15 @@ const runMigration01 = () =>
|
|||||||
ADD COLUMN IF NOT EXISTS semantic_description TEXT
|
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
|
// Wrapper for most queries for JIT table creation/migration running
|
||||||
const safelyQueryPhotos = async <T>(
|
const safelyQueryPhotos = async <T>(
|
||||||
callback: () => Promise<T>,
|
callback: () => Promise<T>,
|
||||||
@ -84,6 +95,13 @@ const safelyQueryPhotos = async <T>(
|
|||||||
console.log('Running migration 01 ...');
|
console.log('Running migration 01 ...');
|
||||||
await runMigration01();
|
await runMigration01();
|
||||||
result = await callback();
|
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)) {
|
} else if (/relation "photos" does not exist/i.test(e.message)) {
|
||||||
// If the table does not exist, create it
|
// If the table does not exist, create it
|
||||||
console.log('Creating photos table ...');
|
console.log('Creating photos table ...');
|
||||||
@ -131,6 +149,8 @@ export const insertPhoto = (photo: PhotoDbInsert) =>
|
|||||||
model,
|
model,
|
||||||
focal_length,
|
focal_length,
|
||||||
focal_length_in_35mm_format,
|
focal_length_in_35mm_format,
|
||||||
|
lens_make,
|
||||||
|
lens_model,
|
||||||
f_number,
|
f_number,
|
||||||
iso,
|
iso,
|
||||||
exposure_time,
|
exposure_time,
|
||||||
@ -158,6 +178,8 @@ export const insertPhoto = (photo: PhotoDbInsert) =>
|
|||||||
${photo.model},
|
${photo.model},
|
||||||
${photo.focalLength},
|
${photo.focalLength},
|
||||||
${photo.focalLengthIn35MmFormat},
|
${photo.focalLengthIn35MmFormat},
|
||||||
|
${photo.lensMake},
|
||||||
|
${photo.lensModel},
|
||||||
${photo.fNumber},
|
${photo.fNumber},
|
||||||
${photo.iso},
|
${photo.iso},
|
||||||
${photo.exposureTime},
|
${photo.exposureTime},
|
||||||
@ -188,6 +210,8 @@ export const updatePhoto = (photo: PhotoDbInsert) =>
|
|||||||
model=${photo.model},
|
model=${photo.model},
|
||||||
focal_length=${photo.focalLength},
|
focal_length=${photo.focalLength},
|
||||||
focal_length_in_35mm_format=${photo.focalLengthIn35MmFormat},
|
focal_length_in_35mm_format=${photo.focalLengthIn35MmFormat},
|
||||||
|
lens_make=${photo.lensMake},
|
||||||
|
lens_model=${photo.lensModel},
|
||||||
f_number=${photo.fNumber},
|
f_number=${photo.fNumber},
|
||||||
iso=${photo.iso},
|
iso=${photo.iso},
|
||||||
exposure_time=${photo.exposureTime},
|
exposure_time=${photo.exposureTime},
|
||||||
|
|||||||
@ -103,6 +103,8 @@ const FORM_METADATA = (
|
|||||||
},
|
},
|
||||||
focalLength: { label: 'focal length' },
|
focalLength: { label: 'focal length' },
|
||||||
focalLengthIn35MmFormat: { label: 'focal length 35mm-equivalent' },
|
focalLengthIn35MmFormat: { label: 'focal length 35mm-equivalent' },
|
||||||
|
lensMake: { label: 'lens make' },
|
||||||
|
lensModel: { label: 'lens model' },
|
||||||
fNumber: { label: 'aperture' },
|
fNumber: { label: 'aperture' },
|
||||||
iso: { label: 'ISO' },
|
iso: { label: 'ISO' },
|
||||||
exposureTime: { label: 'exposure time' },
|
exposureTime: { label: 'exposure time' },
|
||||||
@ -195,6 +197,8 @@ export const convertExifToFormData = (
|
|||||||
model: data.tags?.Model,
|
model: data.tags?.Model,
|
||||||
focalLength: data.tags?.FocalLength?.toString(),
|
focalLength: data.tags?.FocalLength?.toString(),
|
||||||
focalLengthIn35MmFormat: data.tags?.FocalLengthIn35mmFormat?.toString(),
|
focalLengthIn35MmFormat: data.tags?.FocalLengthIn35mmFormat?.toString(),
|
||||||
|
lensMake: data.tags?.LensMake,
|
||||||
|
lensModel: data.tags?.LensModel,
|
||||||
fNumber: data.tags?.FNumber?.toString(),
|
fNumber: data.tags?.FNumber?.toString(),
|
||||||
iso: data.tags?.ISO?.toString(),
|
iso: data.tags?.ISO?.toString(),
|
||||||
exposureTime: data.tags?.ExposureTime?.toString(),
|
exposureTime: data.tags?.ExposureTime?.toString(),
|
||||||
|
|||||||
@ -48,6 +48,8 @@ export interface PhotoExif {
|
|||||||
model?: string
|
model?: string
|
||||||
focalLength?: number
|
focalLength?: number
|
||||||
focalLengthIn35MmFormat?: number
|
focalLengthIn35MmFormat?: number
|
||||||
|
lensMake?: string
|
||||||
|
lensModel?: string
|
||||||
fNumber?: number
|
fNumber?: number
|
||||||
iso?: number
|
iso?: number
|
||||||
exposureTime?: number
|
exposureTime?: number
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user