]> git.sesse.net Git - pr0n/blobdiff - sql/pr0n.sql
Fix an (irrelevant) confusion about addEventListener.
[pr0n] / sql / pr0n.sql
index f3f2087e6ce7b8d7db298c1d60841d4d655868a4..d3541ed27656b7d420995cae56c14b16d1cb1561 100644 (file)
@@ -34,8 +34,16 @@ CREATE TABLE images (
     selected boolean DEFAULT false,
     model character varying,
     lens character varying,
+    is_render boolean NOT NULL DEFAULT false,  -- Is this a render of another picture? (If so, don't show it separately.)
+    render_id integer,  -- If not NULL, show this picture instead of ourselves for all JPEG-creation purposes.
 
-    FOREIGN KEY (vhost,event) REFERENCES events (vhost,event)
+    FOREIGN KEY (vhost,event) REFERENCES events (vhost,event),
+    FOREIGN KEY (vhost,event,render_id) REFERENCES images (vhost,event,id),
+
+    -- Redundant with the primary key, but the foreign key needs it.
+    UNIQUE (vhost,event,id),
+
+    CHECK (NOT (is_render AND (render_id IS NOT NULL)))
 );
 CREATE UNIQUE INDEX unique_filenames ON images USING btree (vhost, event, filename);
 
@@ -52,6 +60,8 @@ CREATE TABLE deleted_images (
     selected boolean,
     model character varying,
     lens character varying
+    is_render boolean NOT NULL,
+    render_id integer,
 );
 
 CREATE TABLE users (
@@ -61,7 +71,8 @@ CREATE TABLE users (
 );
 
 -- Mainly used for manual queries -- usually too slow to be very useful
--- for web views in the long run.
+-- for web views in the long run (except for the special case of the
+-- partial index below).
 CREATE TABLE exif_info (
     image integer NOT NULL REFERENCES images (id) ON DELETE CASCADE,
     key varchar NOT NULL,
@@ -70,8 +81,10 @@ CREATE TABLE exif_info (
     PRIMARY KEY ( image, key )
 );
 
-CREATE INDEX exif_info_key ON exif_info ( key );
-CLUSTER exif_info_key ON exif_info;
+CLUSTER exif_info_pkey ON exif_info;
+CREATE UNIQUE INDEX exif_info_fast_listing ON exif_info (image, key) INCLUDE (value)
+  WHERE key IN ('ExposureProgram', 'FocalLength', 'ExposureTime', 'FNumber', 'ISO', 'ISOSetting',
+                'ExposureBiasValue', 'ExposureCompensation', 'DateTimeOriginal', 'Model', 'Flash');
 
 GRANT INSERT ON TABLE deleted_images TO pr0n;
 GRANT INSERT,SELECT,UPDATE,DELETE ON TABLE events TO pr0n;