2 -- Upgrades pre-v2.50 databases to 2.50 format.
6 ALTER TABLE exif_info RENAME COLUMN tag TO key;
7 CREATE INDEX exif_info_key ON exif_info ( key );
8 CLUSTER exif_info_key ON exif_info;
11 image integer NOT NULL REFERENCES images (id) ON DELETE CASCADE,
14 PRIMARY KEY ( image, tag )
16 CREATE INDEX tags_tag ON tags ( tag );
18 GRANT SELECT,INSERT,DELETE ON TABLE tags TO pr0n;
20 -- width/height -1 => NULL
21 ALTER TABLE images ALTER COLUMN width DROP NOT NULL;
22 ALTER TABLE images ALTER COLUMN height DROP NOT NULL;
23 ALTER TABLE images ALTER COLUMN width SET DEFAULT NULL;
24 ALTER TABLE images ALTER COLUMN height SET DEFAULT NULL;
25 UPDATE images SET width=NULL,height=NULL WHERE width=-1 OR height=-1;
26 ALTER TABLE images ADD CONSTRAINT width_height_nullity CHECK ((width IS NULL) = (height IS NULL));
28 ALTER TABLE deleted_images ALTER COLUMN width DROP NOT NULL;
29 ALTER TABLE deleted_images ALTER COLUMN height DROP NOT NULL;
30 ALTER TABLE deleted_images ALTER COLUMN width SET DEFAULT NULL;
31 ALTER TABLE deleted_images ALTER COLUMN height SET DEFAULT NULL;
32 UPDATE deleted_images SET width=NULL,height=NULL WHERE width=-1 OR height=-1;
33 ALTER TABLE deleted_images ADD CONSTRAINT width_height_nullity CHECK ((width IS NULL) = (height IS NULL));
35 -- model/lens denormalization (reduce usage of exif_info)
36 ALTER TABLE images ADD COLUMN model varchar;
37 ALTER TABLE images ADD COLUMN lens varchar;
38 UPDATE images SET lens=COALESCE(
40 SELECT value FROM exif_info WHERE key='Lens' AND images.id=exif_info.image
43 SELECT value FROM exif_info WHERE key='LensSpec' AND images.id=exif_info.image
46 SELECT value FROM exif_info WHERE key='Model' AND images.id=exif_info.image
48 UPDATE images SET model=NULL WHERE model='';
49 UPDATE images SET lens=NULL WHERE lens='';
51 ALTER TABLE deleted_images ADD COLUMN model varchar;
52 ALTER TABLE deleted_images ADD COLUMN lens varchar;
53 UPDATE deleted_images SET lens=COALESCE(
55 SELECT value FROM exif_info WHERE key='Lens' AND deleted_images.id=exif_info.image
58 SELECT value FROM exif_info WHERE key='LensSpec' AND deleted_images.id=exif_info.image
61 SELECT value FROM exif_info WHERE key='Model' AND deleted_images.id=exif_info.image
63 UPDATE deleted_images SET model=NULL WHERE model='';
64 UPDATE deleted_images SET lens=NULL WHERE lens='';