-- Non-destructive photo editing: the parameters live in the photo metadata and -- the edited image is stored as separate objects next to the base variants. ALTER TABLE photos ADD COLUMN IF NOT EXISTS edit_params jsonb NOT NULL DEFAULT '{}'::jsonb; 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', 'playback', 'edit', 'edit_thumb', 'edit_medium', 'edit_preview')); -- Durable queue of pending edit renders, one job per photo. CREATE TABLE IF NOT EXISTS edit_jobs ( photo_id text PRIMARY KEY REFERENCES photos(id) ON DELETE CASCADE, attempts integer NOT NULL DEFAULT 0, next_attempt_at timestamptz NOT NULL DEFAULT now(), last_error text NOT NULL DEFAULT '', created_at timestamptz NOT NULL DEFAULT now() ); CREATE INDEX IF NOT EXISTS edit_jobs_due_idx ON edit_jobs (next_attempt_at);