9.1 KiB
9.1 KiB
RethinkDB Database Schema
Database tinode
Table users
Stores user accounts
Fields:
Iduser id, primary keyCreatedAttimestamp when the user was createdUpdatedAttimestamp when user metadata was updatedStateaccount state: normal (ok), suspended, soft-deletedStateAttimestamp when the state was last updated or NULLAccessuser's default access level for peer-to-peer topicsAuth,Anondefault permissions for authenticated and anonymous usersPublicapplication-defined dataStatestate of the user: normal, disabled, deletedStateAttimestamp when the state was last updated or NULLLastSeentimestamp when the user was last onlineUserAgentclient User-Agent used when last onlineTagsunique strings for user discoveryDevicesclient devices for push notificationsDeviceIddevice registration IDPlatformdevice platform string (iOS, Android, Web)LastSeenlast logged inLangdevice language, ISO code
Indexes:
Idprimary keyTagsmulti-index (indexed array)DeletedAtindexDeviceIdsmulti-index of push notification tokens
Sample:
{
"Access": {
"Anon": 0 ,
"Auth": 47
} ,
"CreatedAt": Mon Jul 24 2017 11:16:38 GMT+00:00 ,
"State": 0,
"StateAt": null ,
"Devices": null ,
"Id": "7yUCHniegrM" ,
"LastSeen": Mon Jan 01 1 00:00:00 GMT+00:00 ,
"Public": {
"fn": "Alice Johnson" ,
"photo": {
"data": <binary, 6.5KB, "ff d8 ff e0 00 10..."> ,
"type": "jpg"
}
} ,
"State": 1 ,
"Tags": [
"email:alice@example.com" ,
"tel:17025550001"
] ,
"UpdatedAt": Mon Jul 24 2017 11:16:38 GMT+00:00 ,
"UserAgent": "TinodeWeb/0.13 (MacIntel) tinodejs/0.13"
}
Table auth
Stores authentication secrets
Fields:
useridID of the user who owns the recorduniqueunique string which identifies this record, primary key; defined as "authentication scheme':'some unique value per scheme"secretshared secret, for instance bcrypt of passwordauthLvlauthentication levelexpirestimestamp when the records expires
Indexes:
uniqueprimary keyuseridindex
Sample:
{
"authLvl": 20 ,
"expires": Mon Jan 01 1 00:00:00 GMT+00:00 ,
"secret": <binary, 60 bytes, "24 32 61 24 31 30..."> ,
"unique": "basic:alice" ,
"userid": "7yUCHniegrM"
}
Table topics
The table stores topics.
Fields:
Idname of the topic, primary keyCreatedAttopic creation timeUpdatedAttimestamp of the last change to topic metadataStatetopic state: normal (ok), suspended, soft-deletedStateAttimestamp when the state was last updated or NULLAccessstores topic's default access permissionsAuth,Anonpermissions for authenticated and anonymous users respectivelyOwnerID of the user who owns the topicPublicapplication-defined dataStatestate of the topic: normal, disabled, deletedSeqIdsequential ID of the last messageDelIdtopic-sequential ID of the deletion operationUseBtindicator that channel functionality is enabled in the topic
Indexes:
Idprimary keyOwnerindex
Sample:
{
"Access": {
"Anon": 64 ,
"Auth": 64
} ,
"DelId": 0,
"CreatedAt": Thu Oct 15 2015 04:06:51 GMT+00:00 ,
"State": 0 ,
"StateAt": null ,
"LastMessageAt": Sat Oct 17 2015 13:51:56 GMT+00:00 ,
"Id": "p2pavVGHLCBbKrvJQIeeJ6Csw" ,
"Owner": "v2JyG4OLSoA" ,
"Public": {
"fn": "Travel, travel, travel" ,
"photo": {
"data": <binary, 6.2KB, "ff d8 ff e0 00 10..."> ,
"type": "jpg"
}
} ,
"SeqId": 14,
"State": 0 ,
"UpdatedAt": Thu Oct 15 2015 04:06:51 GMT+00:00 ,
"UseBt": false
}
Table subscriptions
The table stores relationships between users and topics.
Fields:
Idused for object retrievalCreatedAttimestamp when the subscription was createdUpdatedAttimestamp when the subscription was updatedDeletedAttimestamp when the subscription was deletedReadSeqIdid of the message last read by the userRecvSeqIdid of the message last received by any user deviceDelIdtopic-sequential ID of the soft-deletion operationTopicname of the topic subscribed toUsersubscriber's user IDModeWantaccess mode that user wants when accessing the topicModeGivenaccess mode granted to user by the topicPrivateapplication-defined data, accessible by the user only
Indexes:
Idprimary key composed as "topic name':'user ID"UserindexTopicindex
Sample:
{
"ClearId": 0 ,
"CreatedAt": Tue Jul 25 2017 15:34:39 GMT+00:00 ,
"DeletedAt": null ,
"Id": "grpjajVKrHn0PU:v2JyG4OLSoA" ,
"ModeGiven": 47 ,
"ModeWant": 47 ,
"Private": "Kirgudu" ,
"ReadSeqId": 0 ,
"RecvSeqId": 0 ,
"State": 0 ,
"Topic": "grpjajVKrHn0PU" ,
"UpdatedAt": Tue Jul 25 2017 15:34:39 GMT+00:00 ,
"User": "v2JyG4OLSoA"
}
Table messages
The table stores {data} messages
Fields:
Idcurrently unused, primary keyCreatedAttimestamp when the message was createdUpdatedAtinitially equal to CreatedAt, for deleted messages equal to DeletedAtDeletedForarray of user IDs which soft-deleted the messageDelIdtopic-sequential ID of the soft-deletion operationUserID of the user who soft-deleted the messageFromID of the user who generated this messageTopicwhich received this messageSeqIdmessages ID - sequential number of the message in the topicHeadmessage headersAttachmentsdenormalized IDs of files attached to the messageContentapplication-defined message payload
Indexes:
Idprimary keyTopic_SeqIdcompound index["Topic", "SeqId"]Topic_DelIdcompound index["Topic", "DelId"]Topic_DeletedForcompound multi-index["Topic", "DeletedFor"("User"), "DeletedFor"("DelId")]
Sample:
{
"Content": {
"fmt": [
{
"len": 6 ,
"tp": "ST"
}
] ,
"txt": "Hello!"
} ,
"CreatedAt": Sun Dec 24 2017 05:16:23 GMT+00:00 ,
"From": "wTI0jO9rEqY" ,
"Head": {
"mime": "text/x-drafty"
} ,
"DeletedFor": [
{
"DelId": 1 ,
"User": "wTI0jO9rEqY"
}
] ,
"Id": "LLXKEe9W4Bs" ,
"SeqId": 3 ,
"Topic": "p2pJhbJnya8z5PBMjSM72sSpg" ,
"UpdatedAt": Sun Dec 24 2017 05:16:23 GMT+00:00
}
Table dellog
The table stores records of message deletions
Fields:
Idcurrently unused, primary keyCreatedAttimestamp when the record was createdUpdatedAttimestamp equal to CreatedAtDelIdtopic-sequential ID of the deletion operation.DeletedForID of the user for soft-deletions, blank string for hard-deletionsTopicaffected topicSeqIdRangesarray of ranges of deleted message IDs (seemessages.SeqId)
Indexes:
Idprimary keyTopic_DelIdcompound index["Topic", "DelId"]
Sample:
{
"Id": "9LfrjW349Rc",
"CreatedAt": Tue Dec 05 2017 01:51:38 GMT+00:00,
"DelId": 18,
"DeletedFor": "xY-YHx09-WI" ,
"SeqIdRanges": [
{
"Low": 20,
"Hi": 25,
}
] ,
"Topic": "grpGx7fpjQwVC0" ,
"UpdatedAt": Tue Dec 05 2017 01:51:38 GMT+00:00
}
Table credentials
The tables stores user credentials used for validation.
Idcredential, primary keyCreatedAttimestamp when the record was createdUpdatedAttimestamp when the last validation attempt was performed (successful or not).Methodvalidation methodDoneindicator if the credential is validatedRespexpected validation responseRetriesnumber of failed attempts at validationUserid of the user who owns this credentialValuevalue of the credentialClosedunvalidated credential is no longer being validated. Only one credential is not Closed for each user/method.
Indexes:
IdPrimary key composed either asUser:Method:Valuefor unconfirmed credentials or asMethod:Valuefor confirmed.UserIndex
Sample:
{
"Id": "tel:+17025550001",
"CreatedAt": Sun Jun 10 2018 16:37:27 GMT+00:00 ,
"UpdatedAt": Sun Jun 10 2018 16:37:28 GMT+00:00 ,
"Method": "tel" ,
"Done": true ,
"Resp": "123456" ,
"Retries": 0 ,
"User": "k3srBRk9RYw" ,
"Value": "+17025550001"
}
Table fileuploads
The table stores records of uploaded files. The files themselves are stored outside of the database.
Idunique user-visible file name, primary keyCreatedAttimestamp when the record was createdUpdatedAttimestamp of when th upload has cmpleted or failedUserid of the user who uploaded this file.Locationactual location of the file on the server.MimeTypefile content type as a Mime string.Sizesize of the file in bytes. Could be 0 if upload has not completed yet.UseCountcount of messages referencing this file.Statusupload status: 0 pending, 1 completed, -1 failed.
Indexes:
Idprimary keyUseCountindex
Sample:
{
"CreatedAt": Sun Jun 10 2018 16:38:45 GMT+00:00 ,
"Id": "sFmjlQ_kA6A" ,
"Location": "uploads/sFmjlQ_kA6A" ,
"MimeType": "image/jpeg" ,
"Size": 54961090 ,
"UseCount": 3,
"Status": 1,
"UpdatedAt": Sun Jun 10 2018 16:38:45 GMT+00:00 ,
"User": "7j-RR1V7O3Y"
}