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

--- add columns
ALTER TABLE telegram_channels ADD bot_token VARCHAR(255);
ALTER TABLE telegram_channels ADD created_at DATETIMEOFFSET NOT NULL DEFAULT SYSDATETIMEOFFSET();
ALTER TABLE telegram_channels ADD updated_at DATETIMEOFFSET NOT NULL DEFAULT SYSDATETIMEOFFSET();

--- 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 VARCHAR(255) NOT NULL;

--- create indexes
CREATE UNIQUE INDEX tg_channels_bot_token_uniq
  ON telegram_channels (bot_token)
  WHERE deleted = 0;

--- remove old indexes
DROP INDEX channels_telegram_bot_token_uniq ON channels;

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