--- schema-cleanup

-- Channels
ALTER TABLE channels
  DROP COLUMN event_id,
  DROP COLUMN total_members,
  DROP COLUMN total_chats,
  DROP COLUMN total_open_chats,
  DROP COLUMN chat_event_id,
  DROP COLUMN apns_id;

ALTER TABLE channel_messages
  DROP CONSTRAINT channel_messages_event_id_fkey,
  DROP CONSTRAINT channel_messages_session_id_fkey;

ALTER TABLE channel_thread_events
  DROP CONSTRAINT channel_events_message_id_fkey,
  DROP CONSTRAINT channel_thread_events_session_id_fkey;

ALTER TABLE channel_threads
  DROP CONSTRAINT channel_threads_event_id_fkey,
  DROP CONSTRAINT channel_threads_message_id_fkey,
  DROP CONSTRAINT channel_threads_session_id_fkey;

DROP TABLE channel_apns;
DROP TABLE channel_events;
DROP TABLE channel_members;
DROP TABLE channel_messages;
DROP TABLE channel_thread_events;
DROP TABLE channel_thread_members;
DROP TABLE channel_thread_sessions;
DROP TABLE channel_threads;

-- Chats
ALTER TABLE chats
  DROP COLUMN "open",
  DROP COLUMN message_id,
  DROP COLUMN session_id,
  DROP COLUMN assignee_id,
  DROP COLUMN user_unread,
  DROP COLUMN total_members,
  DROP COLUMN opened_at,
  DROP COLUMN closed_at;

ALTER TABLE chat_messages
  DROP COLUMN uid,
  DROP COLUMN session_id,
  DROP COLUMN "public",
  DROP COLUMN notice_id,
  DROP COLUMN autoreply_id;

ALTER TABLE chat_events
  DROP COLUMN member_id,
  DROP COLUMN inbox_id,
  DROP COLUMN thread_id;

ALTER TABLE chat_notices
  DROP CONSTRAINT chat_notices_member_id_fkey;

DROP TABLE chat_channel_events;
DROP TABLE chat_client_events;
DROP TABLE chat_event_tree;

DROP TABLE chat_inboxes;
DROP TABLE chat_members;
DROP TABLE chat_notices;
DROP TABLE chat_sessions;

DROP TABLE chat_user_changes;
DROP TABLE chat_user_events;
DROP TABLE chat_user_inbox_changes;
DROP TABLE chat_user_inboxes;
DROP TABLE chat_user_thread_changes;
DROP TABLE chat_user_threads;

-- Events
DROP TABLE event_subscribers;

-- Facebook
ALTER TABLE facebook_users
  DROP COLUMN client_id;

-- Inboxes
ALTER TABLE inbox_threads
  DROP COLUMN message_id;

-- Projects
DROP TABLE project_members;
DROP TABLE project_roles;

-- Stats
DROP TABLE stats_channels;

-- Sys
ALTER TABLE sys_queue_consumers
  DROP COLUMN collected_at;

DROP TABLE sys_queue_items;

-- Users
ALTER TABLE user_events
  DROP CONSTRAINT user_events_group_id_fkey;

ALTER TABLE user_groups_members
  DROP CONSTRAINT user_groups_members_group_id_fkey;

DROP TABLE user_events;
DROP TABLE user_groups;
DROP TABLE user_groups_members;
