 END;
 $$
 LANGUAGE 'plpgsql' IMMUTABLE;
-
-CREATE UNIQUE INDEX downloads_for_extractor_trainer
-    ON downloads ( downloads_id, feeds_id)
-    WHERE file_status <> 'missing' and type = 'content' and state = 'success';
 
 CREATE INDEX downloads_sites_pending on downloads ( site_from_host( host ) ) where state='pending';
 

create index downloads_feed_download_time on downloads ( feeds_id, download_time );

-- create index downloads_sequence on downloads (sequence);
create index downloads_type on downloads (type);
create index downloads_host_state_priority on downloads (host, state, priority);
create index downloads_feed_state on downloads(feeds_id, state);
create index downloads_story on downloads(stories_id);
create index downloads_url on downloads(url);
CREATE INDEX downloads_state_downloads_id_pending on downloads(state,downloads_id) where state='pending';
create index downloads_extracted on downloads(extracted, state, type)
    where extracted = 'f' and state = 'success' and type = 'content';


UPDATE downloads set old_download_time = download_time, old_state = state;


alter table downloads add constraint downloads_parent_fkey
    foreign key (parent) references downloads on delete set null;
