create table peers_telegram_user
(
    federated_address varchar(255) default concat(`id`, 'u@telegram.org') not null comment 'A federated Internet Standard ID for this entity'
        primary key,
    id                bigint                                              not null comment 'Unique identifier for this user or bot. 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 64-bit integer or double-precision float type are safe for storing this identifier.',
    is_bot            tinyint(1)   default 0                              not null comment 'True, if this user is a bot',
    first_name        varchar(255) collate utf8mb4_unicode_ci             null comment 'Optional. User''s or bot''s last name',
    last_name         varchar(255) collate utf8mb4_unicode_ci             null comment 'Optional. User''s or bot''s last name',
    username          varchar(255) collate utf8mb4_unicode_ci             null comment 'Optional. User''s or bot''s username',
    language_code     tinyint(2)                                          null comment 'Optional. IETF language tag of the user''s language',
    is_premium        tinyint(1)   default 0                              not null comment 'Optional. True, if this user is a Telegram Premium user',
    constraint telegram_user_federated_id_uindex
        unique (federated_address),
    constraint telegram_user_pk2
        unique (id),
    constraint telegram_user_discovered_peers_federated_address_fk
        foreign key (federated_address) references peers (federated_address)
)
    comment 'The table for housing Telegram user entity references';

create index telegram_user_username_index
    on peers_telegram_user (username);

