--- create-telegram-messages

CREATE TABLE telegram_messages (
  id                   BIGINT      NOT NULL PRIMARY KEY,
  channel_id           BIGINT      NOT NULL  REFERENCES telegram_channels (id),
  user_id              BIGINT REFERENCES telegram_users (id),
  chat_message_id      BIGINT REFERENCES chat_messages (id),
  telegram_message_id  BIGINT,
  telegram_raw_message VARCHAR,
  out                  BOOLEAN     NOT NULL  DEFAULT FALSE,
  sent                 BOOLEAN     NOT NULL  DEFAULT FALSE,
  created_at           TIMESTAMPTZ NOT NULL  DEFAULT now(),
  sent_at              TIMESTAMPTZ
);

CREATE SEQUENCE telegram_messages_id_seq;