feat(photos): add square medium variant for sharp grid thumbnails

This commit is contained in:
iu
2026-10-11 19:57:00 +03:00
parent 581e479f03
commit f1b3b01bdf
27 changed files with 459 additions and 32 deletions
@@ -0,0 +1,5 @@
-- Drop medium bindings before narrowing the role constraint again.
DELETE FROM photo_objects WHERE role = 'medium';
ALTER TABLE photo_objects DROP CONSTRAINT IF EXISTS photo_objects_role_check;
ALTER TABLE photo_objects ADD CONSTRAINT photo_objects_role_check
CHECK (role IN ('original', 'thumb', 'preview'));
@@ -0,0 +1,11 @@
-- The grid serves a square medium variant between thumb and preview.
ALTER TABLE photo_objects DROP CONSTRAINT IF EXISTS photo_objects_role_check;
ALTER TABLE photo_objects ADD CONSTRAINT photo_objects_role_check
CHECK (role IN ('original', 'thumb', 'medium', 'preview'));
-- Regenerate variants for existing photos so they gain the medium variant and a
-- square thumb. The worker rebinds roles; superseded variants are reclaimed by
-- the reference-counting collector.
INSERT INTO variant_jobs (photo_id)
SELECT id FROM photos
ON CONFLICT (photo_id) DO NOTHING;
@@ -0,0 +1,18 @@
-- Drop medium bindings and restore the original three-role constraint.
DELETE FROM photo_objects WHERE role = 'medium';
CREATE TABLE photo_objects_old (
photo_id TEXT NOT NULL REFERENCES photos(id) ON DELETE CASCADE,
object_id TEXT NOT NULL REFERENCES objects(id) ON DELETE RESTRICT,
role TEXT NOT NULL CHECK (role IN ('original', 'thumb', 'preview')),
PRIMARY KEY (photo_id, role)
);
INSERT INTO photo_objects_old (photo_id, object_id, role)
SELECT photo_id, object_id, role FROM photo_objects;
DROP TABLE photo_objects;
ALTER TABLE photo_objects_old RENAME TO photo_objects;
CREATE INDEX IF NOT EXISTS photo_objects_object_idx ON photo_objects (object_id);
@@ -0,0 +1,24 @@
-- SQLite cannot alter a CHECK constraint, so recreate photo_objects with the
-- extended role set (medium added) and copy the existing bindings across.
CREATE TABLE photo_objects_new (
photo_id TEXT NOT NULL REFERENCES photos(id) ON DELETE CASCADE,
object_id TEXT NOT NULL REFERENCES objects(id) ON DELETE RESTRICT,
role TEXT NOT NULL CHECK (role IN ('original', 'thumb', 'medium', 'preview')),
PRIMARY KEY (photo_id, role)
);
INSERT INTO photo_objects_new (photo_id, object_id, role)
SELECT photo_id, object_id, role FROM photo_objects;
DROP TABLE photo_objects;
ALTER TABLE photo_objects_new RENAME TO photo_objects;
CREATE INDEX IF NOT EXISTS photo_objects_object_idx ON photo_objects (object_id);
-- Regenerate variants for existing photos so they gain the medium variant and a
-- square thumb.
INSERT INTO variant_jobs (photo_id)
SELECT id FROM photos
WHERE 1
ON CONFLICT (photo_id) DO NOTHING;