From: APTX Date: Tue, 3 Jul 2012 12:42:43 +0000 (+0200) Subject: host_id should be an integer. Make file_location unique by fid/host/path rather than... X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=c38fb3fe2a83f1a1b7b68ee9e4cf5b75f94c4273;p=localmylist.git host_id should be an integer. Make file_location unique by fid/host/path rather than just fid. This allows storing all locations of a particular file, find duplicates etc. --- diff --git a/localmylist/share/schema/schema.sql b/localmylist/share/schema/schema.sql index ad6c855..e091f59 100644 --- a/localmylist/share/schema/schema.sql +++ b/localmylist/share/schema/schema.sql @@ -112,11 +112,11 @@ CREATE INDEX file_episode_rel_fid_fk ON file_episode_rel USING btree (fid); CREATE TABLE file_location ( fid integer NOT NULL, - host_id character varying(100), + host_id integer, path text, renamed timestamp without time zone, failed_rename boolean NOT NULL DEFAULT false, - CONSTRAINT file_location_pk PRIMARY KEY (fid ) + CONSTRAINT file_location_pk PRIMARY KEY (fid, host_id, path ) ); CREATE TABLE unknown_file ( @@ -245,7 +245,7 @@ CREATE RULE config_updated_rule AS ON UPDATE TO config DO NOTIFY config_changed; CREATE RULE file_episode_rel_ignore_duplicate AS ON INSERT TO file_episode_rel WHERE (EXISTS (SELECT 1 FROM file_episode_rel WHERE ((file_episode_rel.fid = new.fid) AND (file_episode_rel.eid = new.eid)))) DO INSTEAD NOTHING; COMMENT ON RULE file_episode_rel_ignore_duplicate ON file_episode_rel IS 'Entries to this table are duplicated in exports'; -CREATE RULE file_location_ignore_duplicate AS ON INSERT TO file_location WHERE (EXISTS (SELECT 1 FROM file_location WHERE (file_location.fid = new.fid))) DO INSTEAD NOTHING; +CREATE RULE file_location_ignore_duplicate AS ON INSERT TO file_location WHERE (EXISTS (SELECT 1 FROM file_location WHERE (file_location.fid = new.fid AND file_location.host_id = new.host_id AND file_location.path = new.path))) DO INSTEAD NOTHING; CREATE RULE file_location_update_rule AS ON UPDATE TO file_location DO NOTIFY rename_data_changed; CREATE RULE new_file_location_rule AS ON INSERT TO file_location DO NOTIFY rename_data_changed;