federationlib/database/peers_telegram_user.sql
2023-06-23 03:53:47 -04:00

26 lines
No EOL
2.2 KiB
SQL

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 not 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',
updated_timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this record was last updated',
updated_client varchar(36) not null comment 'The client UUID that last updated the peer''s metadata',
constraint telegram_user_federated_id_uindex
unique (federated_address),
constraint telegram_user_pk2
unique (id),
constraint peers_telegram_user_clients_uuid_fk
foreign key (updated_client) references clients (uuid),
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);