create table peers_telegram_chat
(
    federated_address varchar(255)                            not null comment 'A federated internet standard ID for this Telegram chat'
        primary key,
    id                bigint                                  not null comment 'Unique identifier for this chat. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier.',
    type              varchar(32)                             not null comment 'The type of chat, Type of chat, can be either “group”, “supergroup” or "channel". "private" is not accepted',
    title             varchar(255) collate utf8mb4_unicode_ci null comment 'Optional. Title, for supergroups, channels and group chats',
    username          varchar(255)                            null comment 'Optional. Username, for private chats, supergroups and channels if available',
    is_forum          tinyint(1) default 0                    not null comment 'Optional. True, if the supergroup chat is a forum (has topics enabled)',
    constraint telegram_chat_federated_address_uindex
        unique (federated_address),
    constraint telegram_chat_id_uindex
        unique (id),
    constraint telegram_chat_pk2
        unique (id),
    constraint telegram_chat_discovered_peers_federated_address_fk
        foreign key (federated_address) references peers (federated_address)
)
    comment 'A table for housing telegram chats for channel references';

create index telegram_chat_username_index
    on peers_telegram_chat (username);

