 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';

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;
