drop index sys_queue_messages_queue_id_pending_not_locked_ix on sys_queue_messages;
drop index sys_queue_messages_consumer_id_pending_ix on sys_queue_messages;
CREATE INDEX sys_queue_messages_queue_id_state
    ON sys_queue_messages (queue_id, state);

CREATE INDEX sys_queue_messages_consumer_id_state
    ON sys_queue_messages (consumer_id, state);

-- chats ---
CREATE INDEX chats_client_id_changed_at_ix
    ON chats (client_id, changed_at DESC);
DROP INDEX chats_type_channel_client_uniq on chats;
CREATE UNIQUE INDEX chats_type_channel_client_uniq ON chats ([type], channel_id, client_id, deleted);

-- client-details
CREATE INDEX client_details_client_id_idx on client_details(client_id);

-- channels
DROP INDEX channels_project_id_ix on channels;
CREATE INDEX channels_project_id_type_ix
    ON channels (project_id,type);

-- client-detail-fields
CREATE INDEX client_detail_fields_client_id_ix on client_detail_fields(client_id);

-- ticket-members
CREATE INDEX ticket_members_ticket_id_idx on ticket_members(ticket_id);

-- users
CREATE INDEX users_active_online_busy_idx on users(active,online,busy);