Updated SQL tables

This commit is contained in:
Netkas 2023-06-23 03:53:47 -04:00
parent c93568b8f1
commit f9fd442891
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
8 changed files with 79 additions and 69 deletions

View file

@ -1,29 +0,0 @@
create table associations
(
child_peer varchar(256) not null comment 'The child peer',
parent_peer varchar(256) not null comment 'The parent peer',
type varchar(32) not null comment 'The association type between the parent peer to the child peer',
client_uuid varchar(36) not null comment 'The client UUID that made the association between the two peers',
timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this assoication was made',
constraint associations_child_peer_parent_peer_uindex
unique (child_peer, parent_peer),
constraint associations_child_peer_type_parent_peer_uindex
unique (child_peer, type, parent_peer),
constraint associations_clients_uuid_fk
foreign key (client_uuid) references clients (uuid),
constraint associations_discovered_peers_federated_address_fk
foreign key (child_peer) references peers (federated_address),
constraint associations_discovered_peers_federated_address_fk2
foreign key (parent_peer) references peers (federated_address)
)
comment 'A table used for housing associations detected between peers';
create index associations_child_peer_index
on associations (child_peer);
create index associations_client_uuid_index
on associations (client_uuid);
create index associations_parent_peer_index
on associations (parent_peer);

13
database/content.sql Normal file
View file

@ -0,0 +1,13 @@
create table content
(
reference_document varchar(36) not null comment 'The primary reference document that the content is from'
primary key,
body mediumtext not null comment 'UTF-8 encoding body content, max content length 16MB (16,777,216 bytes)',
content_type tinytext not null comment 'The content type of the body',
priority tinyint(1) default 0 not null comment 'Indicates if the message was sent as a priority',
constraint content_reference_document_uindex
unique (reference_document),
constraint content_query_documents_document_id_fk
foreign key (reference_document) references query_documents (document_id)
)
comment 'The table for housing the content of the messages';

View file

@ -1,12 +1,13 @@
create table peers
(
federated_address varchar(256) not null comment 'The standard federated address of the peer'
federated_address varchar(256) not null comment 'The standard federated address of the peer'
primary key,
client_first_seen varchar(36) not null comment 'The UUID of the client that first discovered the peer',
client_last_seen varchar(36) not null comment 'The UUID of the client that last saw this peer',
active_restriction varchar(36) null comment 'Optional. The UUID of the restriction that is currently active on the peer',
discovered_timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this peer was first discovered',
seen_timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this peer was last seen',
client_first_seen varchar(36) not null comment 'The UUID of the client that first discovered the peer',
client_last_seen varchar(36) not null comment 'The UUID of the client that last saw this peer',
active_restriction varchar(36) null comment 'Optional. The UUID of the restriction that is currently active on the peer',
permission_role tinyint default 5 not null comment 'The permission role assigned to the peer',
discovered_timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this peer was first discovered',
seen_timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp for when this peer was last seen',
constraint discovered_peers_federated_address_uindex
unique (federated_address),
constraint discovered_peers_clients_uuid_fk
@ -25,5 +26,4 @@ create index discovered_peers_client_last_seen_index
on peers (client_last_seen);
create index peers_active_restriction_index
on peers (active_restriction);
on peers (active_restriction);

View file

@ -0,0 +1,16 @@
create table peers_associations
(
child_peer varchar(255) not null comment 'The peer that is used to declare the association to the parent peer',
parent_peer varchar(255) not null comment 'The parent peer that the child peer is associated with',
association_type tinytext not null comment 'The association type between the child peer and the parent peer',
client_uuid varchar(36) not null comment 'The client UUID that made the association between the two peers',
timestamp int default unix_timestamp() not null comment 'The Unix Timestamp for when the client made the association',
constraint peers_associations_child_peer_parent_peer_uindex
unique (child_peer, parent_peer),
constraint peers_associations_clients_uuid_fk
foreign key (client_uuid) references clients (uuid),
constraint peers_associations_peers_federated_address_fk
foreign key (child_peer) references peers (federated_address),
constraint peers_associations_peers_federated_address_fk2
foreign key (parent_peer) references peers (federated_address)
);

View file

@ -1,23 +1,26 @@
create table peers_telegram_chat
(
federated_address varchar(255) not null comment 'A federated internet standard ID for this Telegram chat'
federated_address varchar(255) not null comment 'The primary standard federated address to which this record is associated to what peer'
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
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 tinytext not null comment 'Type of chat, can be either “private”, “group”, “supergroup” or “channel”',
title varchar(255) 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',
first_name varchar(255) null comment 'Optional. First name of the other party in a private chat',
last_name varchar(255) null comment 'Optional. Last name of the other party in a private chat',
is_forum tinyint(1) default 0 null comment 'Optional. True, if the supergroup chat is a forum (has topics enabled)',
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 peers_telegram_chat_federated_address_uindex
unique (federated_address),
constraint telegram_chat_id_uindex
constraint peers_telegram_chat_id_uindex
unique (id),
constraint telegram_chat_pk2
unique (id),
constraint telegram_chat_discovered_peers_federated_address_fk
constraint peers_telegram_chat_clients_uuid_fk
foreign key (updated_client) references clients (uuid),
constraint peers_telegram_chat_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);
comment 'Table for housing metadata information for Telegram Chats';
create index peers_telegram_chat_username_index
on peers_telegram_chat (username);

View file

@ -4,20 +4,23 @@ create table peers_telegram_user
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',
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);
on peers_telegram_user (username);

View file

@ -5,9 +5,12 @@ create table query_documents
subject_type varchar(32) default 'RECON' not null comment 'The subject type of the query document',
client_id varchar(36) not null comment 'The ID of the client that submitted the document',
client_signature varchar(36) null comment 'The authorization token signed with the document by the client',
event_type tinytext not null comment 'The event type that occured',
channel_peer varchar(256) null comment 'Optional. The channel that the content was sent on',
resent_from_peer varchar(256) null comment 'Optional. The original peer that constructed the message, this indicates "from_peer" is resending the content',
from_peer varchar(256) null comment 'Optional. The peer that sent the content',
to_peer varchar(256) null comment 'Optional. The peer that is the intended reciever of the content',
reply_to_peer varchar(256) null comment 'Optional. This indicates the message is a reply to the peer',
proxy_peer varchar(256) null comment 'Optional. The proxy peer used to send the content, may indicates "from_peer" is the original sender.',
retain tinyint default 0 not null comment 'Indicates if this record should be retained or not',
timestamp bigint default unix_timestamp() not null comment 'The Unix Timestamp of the document''s submission (based off the authorization token)',
@ -20,7 +23,11 @@ create table query_documents
constraint query_documents_discovered_peers_federated_address_fk3
foreign key (to_peer) references peers (federated_address),
constraint query_documents_peers_federated_address_fk
foreign key (proxy_peer) references peers (federated_address)
foreign key (proxy_peer) references peers (federated_address),
constraint query_documents_peers_federated_address_fk2
foreign key (resent_from_peer) references peers (federated_address),
constraint query_documents_peers_federated_address_fk3
foreign key (reply_to_peer) references peers (federated_address)
)
comment 'An archive of all the submitted query documents the database received';
@ -36,6 +43,12 @@ create index query_documents_from_peer_index
create index query_documents_proxy_peer_index
on query_documents (proxy_peer);
create index query_documents_reply_to_peer_index
on query_documents (reply_to_peer);
create index query_documents_resent_from_peer_index
on query_documents (resent_from_peer);
create index query_documents_retain_index
on query_documents (retain);
@ -43,5 +56,4 @@ create index query_documents_subject_type_index
on query_documents (subject_type);
create index query_documents_to_peer_index
on query_documents (to_peer);
on query_documents (to_peer);

View file

@ -2,20 +2,16 @@ create table reports
(
report_id varchar(36) default uuid() not null comment 'The UUID V4 for the report''s ID'
primary key,
reference_document varchar(36) not null comment 'The reference document to which this report came from',
type varchar(32) default 'OTHER' not null comment 'The standard report type',
client_uuid varchar(36) not null comment 'The Client UUID responsible for submitting the report to the database',
reporting_peer varchar(256) null comment 'The peer that submitted the report, if empty will assume the client is the reporter.',
target_peer varchar(36) not null comment 'The target peer that the report is against at',
automated tinyint default 0 not null comment 'Indicates if the report was automated or not',
confidence_score float null comment 'The confidence score of the scanner if the report was automated',
reference_document varchar(36) not null comment 'The reference document to which this report came from',
scan_mode varchar(32) null comment 'The scan mode that was used to conduct the automated report',
confidence_score float null comment 'The confidence score of the scanner if the report was automated',
reason text null comment 'The reason for the report',
submission_timestamp bigint default unix_timestamp() null comment 'The Unix Timestamp for when this report was submitted to the database',
constraint reports_report_id_uindex
unique (report_id),
constraint reports_clients_uuid_fk
foreign key (client_uuid) references clients (uuid),
constraint reports_discovered_peers_federated_address_fk
foreign key (reporting_peer) references peers (federated_address),
constraint reports_discovered_peers_federated_address_fk2
@ -25,9 +21,6 @@ create table reports
)
comment 'The table for storing reports made against peers';
create index reports_client_uuid_index
on reports (client_uuid);
create index reports_reference_document_index
on reports (reference_document);
@ -41,5 +34,4 @@ create index reports_target_peer_index
on reports (target_peer);
create index reports_type_index
on reports (type);
on reports (type);