-- This script updates all sequences in a postgres mir database

select 
  CASE WHEN (select max(id) from content)>(select max(id) from uploaded_media)
     THEN setval('media_id_seq', (select max(id) from content))
     ELSE setval('media_id_seq', (select max(id) from uploaded_media))
  END;
select setval('media_folder_id_seq',  (select max(id) from media_folder));
select setval('topic_id_seq',         (select max(id) from topic));
select setval('webdb_users_id_seq',   (select max(id) from webdb_users));
select setval('comment_id_seq',       (select max(id) from comment));
select setval('breaking_id_seq',      (select max(id) from breaking));
select setval('messages_id_seq',      (select max(id) from messages));
select setval('media_type_id_seq',    (select max(id) from media_type));
select setval('comment_status_id_seq',(select max(id) from comment_status));
select setval('article_type_id_seq',  (select max(id) from article_type));
select setval('language_id_seq',      (select max(id) from language));
select setval('filter_id_seq',        (select max(id) from filter));
select setval('filter_group_id_seq',  (select max(id) from filter_group));
