--- move-telegram-specific-data-to-telegram-channels

--- add columns
ALTER TABLE telegram_channels ADD bot_token VARCHAR;
ALTER TABLE telegram_channels ADD created_at TIMESTAMPTZ NOT NULL DEFAULT now();
ALTER TABLE telegram_channels ADD updated_at TIMESTAMPTZ NOT NULL DEFAULT now();

--- copy data
UPDATE telegram_channels
SET
  bot_token = channels.telegram_bot_token
FROM channels
WHERE telegram_channels.id = channels.id;

alter table telegram_channels alter column bot_token SET NOT NULL;

--- create indexes
CREATE UNIQUE INDEX tg_channels_page_token_uniq
  ON telegram_channels (bot_token)
  WHERE deleted = FALSE;

--- remove old indexes
DROP INDEX channels_telegram_bot_token_uniq;

--- remove old columns
ALTER TABLE channels DROP COLUMN telegram_bot_token;
