 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 stories_collect_date on stories (collect_date);
create index stories_md on stories(media_id, date_trunc('day'::text, publish_date));
create index stories_language on stories(language);
create index stories_db_row_last_updated on stories( db_row_last_updated );
create index stories_title_hash on stories( md5( title ) );
create index stories_publish_day on stories( date_trunc( 'day', publish_date ) );



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;
