8.4 KiB
8.4 KiB
MongoDB Database Schema
Database tinode
Table users
Stores user accounts
Fields:
_iduser id, primary keycreatedattimestamp when the user was createdupdatedattimestamp when user metadata was updatedaccessuser's default access level for peer-to-peer topicsauth,anondefault permissions for authenticated and anonymous users
publicapplication-defined datastateaccount state: normal (ok), suspended, soft-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 keytagsmultikey-index (indexed array)deletedatindexdeviceidsmultikey-index of push notification tokens
Sample:
{
"access": {
"anon": 0 ,
"auth": 47
} ,
"createdat": "2019-10-11T12:13:14.522Z" ,
"state": 0,
"stateat": null ,
"devices": null ,
"_id": "7yUCHniegrM" ,
"lastseen": "2019-10-11T12:13:14.522Z" ,
"public": {
"fn": "Alice Johnson" ,
"photo": {
"data": Binary('/9j/4AAQSkZJRgAB...'),
"type": "jpg"
}
} ,
"state": 1 ,
"tags": [
"email:alice@example.com" ,
"tel:17025550001"
] ,
"updatedat": "2019-10-11T12:13:14.522Z",
"useragent": "TinodeWeb/0.13 (MacIntel) tinodejs/0.13"
}
Table auth
Stores authentication secrets
Fields:
_idunique string which identifies this record, primary key; defined as "authentication scheme':'some unique value per scheme"useridID of the user who owns the recordsecretshared secret, for instance bcrypt of passwordauthLvlauthentication levelexpirestimestamp when the records expires
Indexes:
_idprimary keyuseridindex
Sample:
{
"_id": "basic:alice" ,
"authLvl": 20 ,
"expires": "2019-10-11T12:13:14.522Z" ,
"secret": Binary('/9j/RgAB...'),
"userid": "7yUCHniegrM"
}
Table topics
The table stores topics.
Fields:
_idname of the topic, primary keycreatedattopic creation timeupdatedattimestamp of the last change to topic metadataaccessstores topic's default access permissionsauth,anonpermissions for authenticated and anonymous users respectively
ownerID of the user who owns the topicpublicapplication-defined datastatetopic state: normal (ok), suspended, soft-deletedstateattimestamp when the state was last updated or NULLseqidsequential ID of the last messagedelidtopic-sequential ID of the deletion operationusebtcurrently unused
Indexes:
_idprimary keyownerindextagsmultikey index
Sample:
{
"access": {
"anon": 64 ,
"auth": 64
} ,
"delid": 0,
"createdat": "2019-10-11T12:13:14.522Z",
"lastmessageat": "2019-10-11T12:13:14.522Z" ,
"id": "p2pavVGHLCBbKrvJQIeeJ6Csw" ,
"owner": "v2JyG4OLSoA" ,
"public": {
"fn": "Travel, travel, travel" ,
"photo": {
"data": Binary('/9j/RgAB...') ,
"type": "jpg"
}
} ,
"seqid": 14,
"state": 0,
"stateat": null,
"updatedat": "2019-10-11T12:13:14.522Z" ,
"usebt": false
}
Table subscriptions
The table stores relationships between users and topics.
Fields:
_idused for object retrievalcreatedattimestamp when the user was createdupdatedattimestamp when user metadata was updateddeletedatcurrently unusedreadseqidid of the message last read by the userrecvseqidid of the message last received by 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:
{
"_id": "grpjajVKrHn0PU:v2JyG4OLSoA" ,
"createdat": "2019-10-11T12:13:14.522Z" ,
"updatedat": "2019-10-11T12:13:14.522Z" ,
"deletedat": null ,
"user": "v2JyG4OLSoA",
"topic": "grpjajVKrHn0PU" ,
"recvseqid": 0 ,
"readseqid": 0 ,
"modewant": 47 ,
"modegiven": 47 ,
"private": "Kirgudu" ,
"state": 0
}
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 message
fromID 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 key
Sample:
{
"_id": "LLXKEe9W4Bs" ,
"createdat": "2019-10-11T12:13:14.522Z" ,
"updatedat": "2019-10-11T12:13:14.522Z",
"deletedfor": [
{
"delid": 1 ,
"user": "wTI0jO9rEqY"
}
] ,
"seqid": 3 ,
"topic": "p2pJhbJnya8z5PBMjSM72sSpg",
"from": "wTI0jO9rEqY" ,
"head": {
"mime": "text/x-drafty"
} ,
"content": {
"fmt": [
{
"len": 6 ,
"tp": "ST"
}
] ,
"txt": "Hello!"
}
}
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": "2019-10-11T12:13:14.522Z",
"updatedat": "2019-10-11T12:13:14.522Z",
"topic": "grpGx7fpjQwVC0",
"delid": 18,
"deletedfor": "xY-YHx09-WI",
"seqidranges": [
{
"low": 20,
"hi": 25
}
]
}
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 credential
Indexes:
_idPrimary key composed either asuser:method:valuefor unconfirmed credentials or asmethod:valuefor confirmed.userIndex
Sample:
{
"Id": "tel:+17025550001",
"CreatedAt": "2019-10-11T12:13:14.522Z",
"UpdatedAt": "2019-10-11T12:13:14.522Z",
"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:
_idfile name, primary keyuserindexusecountindex
Sample:
{
"_id": "sFmjlQ_kA6A" ,
"createdat": "2019-10-11T12:13:14.522Z" ,
"updatedat": "2019-10-11T12:13:14.522Z" ,
"location": "uploads/sFmjlQ_kA6A" ,
"mimetype": "image/jpeg" ,
"size": 54961090 ,
"usecount": 3,
"status": 1 ,
"user": "7j-RR1V7O3Y"
}