Skip to content

Commit 4e69ac6

Browse files
authored
Merge pull request #584 from TristanWasTaken/db
docs: update DatabaseSchema.md
2 parents a181d52 + 3b03792 commit 4e69ac6

File tree

4 files changed

+172
-35
lines changed

4 files changed

+172
-35
lines changed

DatabaseSchema.md

Lines changed: 169 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
# SponsorTimesDB
22

3-
[vipUsers](#vipUsers)
4-
[sponsorTimes](#sponsorTimes)
5-
[userNames](#userNames)
6-
[categoryVotes](#categoryVotes)
7-
[lockCategories](#lockCategories)
8-
[warnings](#warnings)
9-
[shadowBannedUsers](#shadowBannedUsers)
10-
[unlistedVideos](#unlistedVideos)
11-
[config](#config)
12-
[archivedSponsorTimes](#archivedSponsorTimes)
3+
- [vipUsers](#vipusers)
4+
- [sponsorTimes](#sponsortimes)
5+
- [userNames](#usernames)
6+
- [categoryVotes](#categoryvotes)
7+
- [lockCategories](#lockcategories)
8+
- [warnings](#warnings)
9+
- [shadowBannedUsers](#shadowbannedusers)
10+
- [videoInfo](#videoinfo)
11+
- [unlistedVideos](#unlistedvideos)
12+
- [config](#config)
13+
- [archivedSponsorTimes](#archivedsponsortimes)
14+
- [ratings](#ratings)
15+
- [userFeatures](#userFeatures)
16+
- [shadowBannedIPs](#shadowBannedIPs)
17+
- [titles](#titles)
18+
- [titleVotes](#titleVotes)
19+
- [thumbnails](#thumbnails)
20+
- [thumbnailTimestamps](#thumbnailTimestamps)
21+
- [thumbnailVotes](#thumbnailVotes)
1322

1423
### vipUsers
1524
| Name | Type | |
1625
| -- | :--: | -- |
17-
| userID | TEXT | not null |
26+
| userID | TEXT | not null, primary key |
1827

1928
| index | field |
2029
| -- | :--: |
@@ -30,7 +39,7 @@
3039
| votes | INTEGER | not null |
3140
| locked | INTEGER | not null, default '0' |
3241
| incorrectVotes | INTEGER | not null, default 1 |
33-
| UUID | TEXT | not null, unique |
42+
| UUID | TEXT | not null, unique, primary key |
3443
| userID | TEXT | not null |
3544
| timeSubmitted | INTEGER | not null |
3645
| views | INTEGER | not null |
@@ -50,14 +59,16 @@
5059
| sponsorTime_timeSubmitted | timeSubmitted |
5160
| sponsorTime_userID | userID |
5261
| sponsorTimes_UUID | UUID |
53-
| sponsorTimes_hashedVideoID | hashedVideoID, category |
54-
| sponsorTimes_videoID | videoID, service, category, timeSubmitted |
62+
| sponsorTimes_hashedVideoID | service, hashedVideoID, startTime |
63+
| sponsorTimes_videoID | service, videoID, startTime |
64+
| sponsorTimes_videoID_category | videoID, category |
65+
| sponsorTimes_description_gin | description, category |
5566

5667
### userNames
5768

5869
| Name | Type | |
5970
| -- | :--: | -- |
60-
| userID | TEXT | not null |
71+
| userID | TEXT | not null, primary key |
6172
| userName | TEXT | not null |
6273
| locked | INTEGER | not nul, default '0' |
6374

@@ -72,6 +83,7 @@
7283
| UUID | TEXT | not null |
7384
| category | TEXT | not null |
7485
| votes | INTEGER | not null, default 0 |
86+
| id | SERIAL | primary key
7587

7688
| index | field |
7789
| -- | :--: |
@@ -88,6 +100,7 @@
88100
| hashedVideoID | TEXT | not null, default '' |
89101
| reason | TEXT | not null, default '' |
90102
| service | TEXT | not null, default 'YouTube' |
103+
| id | SERIAL | primary key
91104

92105
| index | field |
93106
| -- | :--: |
@@ -102,17 +115,22 @@
102115
| issuerUserID | TEXT | not null |
103116
| enabled | INTEGER | not null |
104117
| reason | TEXT | not null, default '' |
118+
| type | INTEGER | default 0 |
119+
120+
| constraint | field |
121+
| -- | :--: |
122+
| PRIMARY KEY | userID, issueTime |
105123

106124
| index | field |
107125
| -- | :--: |
108-
| warnings_index | userID |
126+
| warnings_index | userID, issueTime, enabled |
109127
| warnings_issueTime | issueTime |
110128

111129
### shadowBannedUsers
112130

113131
| Name | Type | |
114132
| -- | :--: | -- |
115-
| userID | TEXT | not null |
133+
| userID | TEXT | not null, primary key |
116134

117135
| index | field |
118136
| -- | :--: |
@@ -129,8 +147,8 @@
129147

130148
| index | field |
131149
| -- | :--: |
132-
| videoInfo_videoID | timeSubmitted |
133-
| videoInfo_channelID | userID |
150+
| videoInfo_videoID | videoID |
151+
| videoInfo_channelID | channelID |
134152

135153
### unlistedVideos
136154

@@ -142,12 +160,13 @@
142160
| channelID | TEXT | not null |
143161
| timeSubmitted | INTEGER | not null |
144162
| service | TEXT | not null, default 'YouTube' |
163+
| id | SERIAL | primary key
145164

146165
### config
147166

148167
| Name | Type | |
149168
| -- | :--: | -- |
150-
| key | TEXT | not null, unique |
169+
| key | TEXT | not null, unique, primary key |
151170
| value | TEXT | not null |
152171

153172
### archivedSponsorTimes
@@ -160,7 +179,7 @@
160179
| votes | INTEGER | not null |
161180
| locked | INTEGER | not null, default '0' |
162181
| incorrectVotes | INTEGER | not null, default 1 |
163-
| UUID | TEXT | not null, unique |
182+
| UUID | TEXT | not null, unique, primary key |
164183
| userID | TEXT | not null |
165184
| timeSubmitted | INTEGER | not null |
166185
| views | INTEGER | not null |
@@ -173,6 +192,7 @@
173192
| shadowHidden | INTEGER | not null |
174193
| hashedVideoID | TEXT | not null, default '', sha256 |
175194
| userAgent | TEXT | not null, default '' |
195+
| description | TEXT | not null, default '' |
176196

177197
### ratings
178198

@@ -183,22 +203,134 @@
183203
| type | INTEGER | not null |
184204
| count | INTEGER | not null |
185205
| hashedVideoID | TEXT | not null |
206+
| id | SERIAL | primary key
186207

187208
| index | field |
188209
| -- | :--: |
189210
| ratings_hashedVideoID_gin | hashedVideoID |
190211
| ratings_hashedVideoID | hashedVideoID, service |
191212
| ratings_videoID | videoID, service |
192213

214+
### userFeatures
215+
| Name | Type | |
216+
| -- | :--: | -- |
217+
| userID | TEXT | not null |
218+
| feature | INTEGER | not null |
219+
| issuerUserID | TEXT | not null |
220+
| timeSubmitted | INTEGER | not null |
221+
222+
| constraint | field |
223+
| -- | :--: |
224+
| primary key | userID, feature |
225+
226+
| index | field |
227+
| -- | :--: |
228+
| userFeatures_userID | userID, feature |
229+
230+
### shadowBannedIPs
231+
232+
| Name | Type | |
233+
| -- | :--: | -- |
234+
| hashedIP | TEXT | not null, primary key |
235+
236+
### titles
237+
238+
| Name | Type | |
239+
| -- | :--: | -- |
240+
| videoID | TEXT | not null |
241+
| title | TEXT | not null |
242+
| original | INTEGER | default 0 |
243+
| userID | TEXT | not null
244+
| service | TEXT not null |
245+
| hashedVideoID | TEXT | not null |
246+
| timeSubmitted | INTEGER | not null |
247+
| UUID | TEXT | not null, primary key
248+
249+
| index | field |
250+
| -- | :--: |
251+
| titles_timeSubmitted | timeSubmitted |
252+
| titles_userID_timeSubmitted | videoID, service, userID, timeSubmitted |
253+
| titles_videoID | videoID, service |
254+
| titles_hashedVideoID_2 | service, hashedVideoID, timeSubmitted |
255+
256+
### titleVotes
257+
258+
| Name | Type | |
259+
| -- | :--: | -- |
260+
| UUID | TEXT | not null, primary key |
261+
| votes | INTEGER | not null, default 0 |
262+
| locked | INTEGER | not null, default 0 |
263+
| shadowHidden | INTEGER | not null, default 0 |
264+
| verification | INTEGER | default 0 |
265+
| downvotes | INTEGER | default 0 |
266+
| removed | INTEGER | default 0 |
267+
268+
| constraint | field |
269+
| -- | :--: |
270+
| foreign key | UUID references "titles"("UUID")
271+
272+
| index | field |
273+
| -- | :--: |
274+
| titleVotes_votes | UUID, votes
275+
276+
### thumbnails
277+
278+
| Name | Type | |
279+
| -- | :--: | -- |
280+
| UUID | TEXT | not null |
281+
| original | INTEGER | default 0 |
282+
| userID | TEXT | not null |
283+
| service | TEXT | not null |
284+
| hashedVideoID | TEXT | not null |
285+
| timeSubmitted | INTEGER | not null |
286+
| UUID | TEXT | not null, primary key |
287+
288+
| index | field |
289+
| -- | :--: |
290+
| thumbnails_timeSubmitted | timeSubmitted |
291+
| thumbnails_votes_timeSubmitted | videoID, service, userID, timeSubmitted |
292+
| thumbnails_videoID | videoID, service |
293+
| thumbnails_hashedVideoID_2 | service, hashedVideoID, timeSubmitted |
294+
295+
### thumbnailTimestamps
296+
297+
| index | field |
298+
| -- | :--: |
299+
| UUID | TEXT | not null, primary key
300+
| timestamp | INTEGER | not null, default 0
301+
302+
| constraint | field |
303+
| -- | :--: |
304+
| foreign key | UUID references "thumbnails"("UUID")
305+
306+
### thumbnailVotes
307+
308+
| index | field |
309+
| -- | :--: |
310+
| UUID | TEXT | not null, primary key |
311+
| votes | INTEGER | not null, default 0 |
312+
| locked | INTEGER |not null, default 0 |
313+
| shadowHidden | INTEGER | not null, default 0 |
314+
| downvotes | INTEGER | default 0 |
315+
| removed | INTEGER | default 0 |
316+
317+
| constraint | field |
318+
| -- | :--: |
319+
| foreign key | UUID references "thumbnails"("UUID")
320+
321+
| index | field |
322+
| -- | :--: |
323+
| thumbnailVotes_votes | UUID, votes
324+
193325
# Private
194326

195-
[votes](#votes)
196-
[categoryVotes](#categoryVotes)
197-
[sponsorTimes](#sponsorTimes)
198-
[config](#config)
199-
[ratings](#ratings)
200-
[tempVipLog](#tempVipLog)
201-
[userNameLogs](#userNameLogs)
327+
- [votes](#votes)
328+
- [categoryVotes](#categoryVotes)
329+
- [sponsorTimes](#sponsorTimes)
330+
- [config](#config)
331+
- [ratings](#ratings)
332+
- [tempVipLog](#tempVipLog)
333+
- [userNameLogs](#userNameLogs)
202334

203335
### votes
204336

@@ -209,6 +341,7 @@
209341
| hashedIP | TEXT | not null |
210342
| type | INTEGER | not null |
211343
| originalVoteType | INTEGER | not null | # Since type was reused to also specify the number of votes removed when less than 0, this is being used for the actual type
344+
| id | SERIAL | primary key |
212345

213346
| index | field |
214347
| -- | :--: |
@@ -223,10 +356,11 @@
223356
| hashedIP | TEXT | not null |
224357
| category | TEXT | not null |
225358
| timeSubmitted | INTEGER | not null |
359+
| id | SERIAL | primary key |
226360

227361
| index | field |
228362
| -- | :--: |
229-
| categoryVotes_UUID | UUID, userID, hasedIP, category |
363+
| categoryVotes_UUID | UUID, userID, hashedIP, category |
230364

231365
### sponsorTimes
232366

@@ -236,17 +370,17 @@
236370
| hashedIP | TEXT | not null |
237371
| timeSubmitted | INTEGER | not null |
238372
| service | TEXT | not null, default 'YouTube' |
373+
| id | SERIAL | primary key |
239374

240375
| index | field |
241376
| -- | :--: |
242-
| sponsorTimes_hashedIP | hashedIP |
243-
| privateDB_sponsorTimes_videoID_v2 | videoID, service |
377+
| privateDB_sponsorTimes_v4 | videoID, service, timeSubmitted |
244378

245379
### config
246380

247381
| Name | Type | |
248382
| -- | :--: | -- |
249-
| key | TEXT | not null |
383+
| key | TEXT | not null, primary key |
250384
| value | TEXT | not null |
251385

252386
### ratings
@@ -259,6 +393,7 @@
259393
| type | INTEGER | not null |
260394
| timeSubmitted | INTEGER | not null |
261395
| hashedIP | TEXT | not null |
396+
| id | SERIAL | primary key |
262397

263398
| index | field |
264399
| -- | :--: |
@@ -271,6 +406,7 @@
271406
| targetUserID | TEXT | not null |
272407
| enabled | BOOLEAN | not null |
273408
| updatedAt | INTEGER | not null |
409+
| id | SERIAL | primary key |
274410

275411
### userNameLogs
276412

@@ -281,3 +417,4 @@
281417
| oldUserName | TEXT | not null |
282418
| updatedByAdmin | BOOLEAN | not null |
283419
| updatedAt | INTEGER | not null |
420+
| id | SERIAL | primary key |

databases/_upgrade_sponsorTimes_6.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BEGIN TRANSACTION;
22

3-
/* Add new voting field */
3+
/* Add 'locked' field */
44
CREATE TABLE "sqlb_temp_table_6" (
55
"videoID" TEXT NOT NULL,
66
"startTime" REAL NOT NULL,

databases/_upgrade_sponsorTimes_8.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BEGIN TRANSACTION;
22

3-
/* Add Service field */
3+
/* Add 'videoDuration' field */
44
CREATE TABLE "sqlb_temp_table_8" (
55
"videoID" TEXT NOT NULL,
66
"startTime" REAL NOT NULL,

databases/_upgrade_sponsorTimes_9.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BEGIN TRANSACTION;
22

3-
/* Add Service field */
3+
/* Change 'videoDuration' field from INTEGER to REAL */
44
CREATE TABLE "sqlb_temp_table_9" (
55
"videoID" TEXT NOT NULL,
66
"startTime" REAL NOT NULL,

0 commit comments

Comments
 (0)