From: Steinar H. Gunderson Date: Wed, 25 Jul 2007 13:15:44 +0000 (+0200) Subject: Rename "tag" to "key" in exif_info table, and make a small SQL script to do X-Git-Url: https://git.sesse.net/?p=pr0n;a=commitdiff_plain;h=42d4fc8288f205794e964cacb04871ef04f01043;ds=sidebyside Rename "tag" to "key" in exif_info table, and make a small SQL script to do just that. --- diff --git a/perl/Sesse/pr0n/Common.pm b/perl/Sesse/pr0n/Common.pm index 073996f..d73df38 100644 --- a/perl/Sesse/pr0n/Common.pm +++ b/perl/Sesse/pr0n/Common.pm @@ -216,7 +216,7 @@ sub update_image_info { undef, $id) or die "Couldn't delete old EXIF information in SQL: $!"; - my $q = $dbh->prepare('INSERT INTO exif_info (image,tag,value) VALUES (?,?,?)') + my $q = $dbh->prepare('INSERT INTO exif_info (image,key,value) VALUES (?,?,?)') or die "Couldn't prepare inserting EXIF information: $!"; for my $key (keys %$info) { diff --git a/perl/Sesse/pr0n/Index.pm b/perl/Sesse/pr0n/Index.pm index 6c7bc80..39c5da4 100644 --- a/perl/Sesse/pr0n/Index.pm +++ b/perl/Sesse/pr0n/Index.pm @@ -115,17 +115,17 @@ sub handler { if ($model eq '') { # no defined model - $where .= " AND id NOT IN ( SELECT image FROM exif_info WHERE tag='Model' AND TRIM(value)<>'' )"; + $where .= " AND id NOT IN ( SELECT image FROM exif_info WHERE key='Model' AND TRIM(value)<>'' )"; } else { - $where .= " AND id IN ( SELECT image FROM exif_info WHERE tag='Model' AND TRIM(value)=$mq )"; + $where .= " AND id IN ( SELECT image FROM exif_info WHERE key='Model' AND TRIM(value)=$mq )"; } # This doesn't match 1:1 if there's both lens and lensspec, but it should be OK in practice if ($lens eq '') { # no defined lens - $where .= " AND id NOT IN ( SELECT image FROM exif_info WHERE (tag='Lens' OR tag='LensSpec') AND TRIM(value)<>'' )"; + $where .= " AND id NOT IN ( SELECT image FROM exif_info WHERE (key='Lens' OR key='LensSpec') AND TRIM(value)<>'' )"; } else { - $where .= " AND id IN ( SELECT image FROM exif_info WHERE (tag='Lens' OR tag='LensSpec') AND TRIM(value)=$lq )"; + $where .= " AND id IN ( SELECT image FROM exif_info WHERE (key='Lens' OR key='LensSpec') AND TRIM(value)=$lq )"; } } @@ -220,9 +220,9 @@ sub handler { COUNT(*) AS num FROM ( SELECT * FROM images WHERE vhost=? $where ) i LEFT JOIN exif_info model ON i.id=model.image - LEFT JOIN ( SELECT * FROM exif_info WHERE tag='Lens' ) lens ON i.id=lens.image - LEFT JOIN ( SELECT * FROM exif_info WHERE tag='LensSpec') lens_spec ON i.id=lens_spec.image - WHERE model.tag='Model' + LEFT JOIN ( SELECT * FROM exif_info WHERE key='Lens' ) lens ON i.id=lens.image + LEFT JOIN ( SELECT * FROM exif_info WHERE key='LensSpec') lens_spec ON i.id=lens_spec.image + WHERE model.key='Model' GROUP BY 1,2 ORDER BY 1,2") or die "Couldn't prepare to find equipment: $!"; diff --git a/sql/pr0n.sql b/sql/pr0n.sql index 5eacc40..c65d1ca 100644 --- a/sql/pr0n.sql +++ b/sql/pr0n.sql @@ -73,14 +73,14 @@ CREATE TABLE users ( CREATE TABLE exif_info ( image integer NOT NULL REFERENCES images (id) ON DELETE CASCADE, - tag varchar NOT NULL, + key varchar NOT NULL, value varchar NOT NULL, - PRIMARY KEY ( image, tag ) + PRIMARY KEY ( image, key ) ); -CREATE INDEX exif_info_tag ON exif_info ( tag ); -CLUSTER exif_info_tag ON exif_info; +CREATE INDEX exif_info_key ON exif_info ( key ); +CLUSTER exif_info_key ON exif_info; GRANT INSERT ON TABLE deleted_images TO pr0n; GRANT INSERT,SELECT,UPDATE,DELETE ON TABLE events TO pr0n; diff --git a/sql/upgrade-v2.50.sql b/sql/upgrade-v2.50.sql new file mode 100644 index 0000000..6f740fe --- /dev/null +++ b/sql/upgrade-v2.50.sql @@ -0,0 +1,7 @@ +-- +-- Upgrades pre-v2.50 databases to 2.50 format -- not many changes, though. +-- +ALTER TABLE exif_info RENAME COLUMN tag TO key; +CREATE INDEX exif_info_key ON exif_info ( key ); +CLUSTER exif_info_key ON exif_info; +