-
Notifications
You must be signed in to change notification settings - Fork 43
/
database-structure.json
152 lines (151 loc) · 5.57 KB
/
database-structure.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//This is an example of structure in Firestore for a social-media structure with likes, comments and posts
//Feel free to commit, or suggest changes.
{
//Collection
"Posts": {
//Documents
"postId_1": {
//Post POJO
"creationDate": "15 of october, 2017 11:17:25 UTC+2",
"commentsCount": 1,
"likesCount": 1,
"content": "content",
"author": {
"fullname": "User 1",
"photoUrl": "https://.....",
"uid": "userId_1"
},
//Sub-collections
"Comments": {
//Documents
"commentId_1 ": {
"author": {
"fullname": "User 2",
"photoUrl": "https://.....",
"uid": "userId_2"
},
"postAuthorId": "userId_1",
//Keep track of the author of the post, to avoid nested queries later
"text": "Test comment",
"timestamp": "15 of october, 2017 15:17:25 UTC+2"
}
},
"Likes": {
//Documents
"likeId_1": {
"author": {
"fullname": "User 2",
"photoUrl": "https://.....",
"uid": "userId_2"
},
"postAuthorId": "userId_1",
//Keep track of the author of the post, to avoid nested queries later
"timestamp": "15 of october, 2017 15:17:25 UTC+2"
}
}
},
"postId_2": {},
"postId_3": {},
//Collection
"PrivateUserData": {
//Documents
"userId_1": {
"accountCreationDate": "10 of october, 2017, 16:04:37 UTC+2",
"email": "test@gmail.com",
"photoUrl": "https://.....",
"lastLogin": "12 of october, 2017, 13:04:37 UTC+2",
"messagingTokens": [
"messagingToken_1",
"messagingToken_2"
],
//Feed is a subcollection which contains denormalized data from the posts of the users that we are following
//You could save here just the Id's and later go for a nested query or store the whole POJO, when we are using
//Firebase Firestore and we will pay in order of the number or operations, I will suggest denormalized the data
//and later edit the data with atomic functions (when the username or photoUrl are changed, or the post is edited)
//In the end an user doesn't change their profile picture or name quite often, so even if it's an expensive update for a
//lot of references, it will be lower than go for nested queries every time we will retrieve posts, comments, likes...
"Feed": {
//Same data than original pojo
"postId-1": {
"creationDate": "15 of october, 2017 11:17:25 UTC+2",
"commentsCount": 1,
"likesCount": 1,
"content": "content",
"author": {
"fullname": "User 1",
"photoUrl": "https://.....",
"uid": "userId_1"
}
},
"postId-2": {}
},
//Events is a subcollection which contains information about the social events from an user, such as new followers,
//comments, likes.... also it's a way to keep track that your user already have been notified for that kind of event.
// If there is already an event of type "Follow" from the User 2, even if he unfollow, and follow our user again, we will
//know that there is no need to send a notificacion again.
"Events": {
//Documents
"eventId_1": {
"kind": "follow",
"interactionUserName": "User 2",
"interactionUserProfilePicture": "https://.....",
"interactionUserId": "userId_2",
"interactionRef": "userId_2",
//Here we are storing the key that we will need for the notification intent. An userId for follows, and a PostId for comments or likes.
"timestamp": "15 of october, 2017 11:17:25 UTC+2"
}
},
//The next three subcollections are just to keep references from the places where we have denormalized data for this user, in this way we could retrieve later the comments,
//likes and posts to update the reference if needed. In other hand, the events could be also stored here, but right now we can query the by interactionUserId.
//In the same way with the Followers and Following from PublicUserData, we have the ids already stored there. We just need to retrieve them and edit the denormalized data.
"AuthorOfComments": {
"commentId_1": {
"timeStamp": "15 of october, 2017 11:17:25 UTC+2"
}
},
"AuthorOfLikes": {
"likeId_1": {
"timeStamp": "15 of october, 2017 11:17:25 UTC+2"
}
},
"AuthorOfPosts": {
"postId_1": {
"timeStamp": "15 of october, 2017 11:17:25 UTC+2"
}
}
}
},
"userId_2": {},
"userId_3": {}
},
//Collection
"PublicUserData": {
//Documents
"userId_1": {
"followersCount": 3,
"followingCount": 1,
"photoUrl": "https://.....",
"username": "User 1",
//Sub-collections
"Followers": {
//If you know that your followers and following will never grow to much(around more than 36K of keys)
//and surpass the Firestore 1MB document limit, you could store the Id's and the denormalized data in an array.
"userId_2": {
"photoUrl": "https://.....",
"username": "User 2"
}
},
"Following": {
//Documents
"userId_3": {
"photoUrl": "https://.....",
"username": "User 3"
}
}
},
"userId_2": {
},
"userId_3": {
}
}
}