--- chat-message-pushed

ALTER TABLE chat_messages
  ADD pushed BOOLEAN NOT NULL DEFAULT FALSE;

UPDATE chat_messages
SET pushed = TRUE;

CREATE INDEX chat_messages_chat_id_notreceived_notpushed_user_ix
  ON chat_messages (chat_id, id)
  WHERE
    received = FALSE
    AND pushed = FALSE
    AND author = 'user';

-- pushes
DROP INDEX pushes_client_id_state_created_at_ix;

CREATE INDEX pushes_message_id_enqueued_ix
  ON pushes (message_id)
  WHERE state = 'enqueued';
