1 -- Tribler SQLite Database
5 -- v1: Published as part of Tribler 4.5
6 -- v2: Published as part of Tribler 5.0
7 -- v3: Published as part of Next-Share M16
8 -- v4: Published as part of Tribler 5.2
9 -- v5: Published as part of Next-Share M30 for subtitles integration
12 -- See Tribler/Core/CacheDB/sqlitecachedb.py updateDB() for exact version diffs.
14 -- v4: ChannelCast is an extension of the concept of ModerationCast, with
15 -- an additional integrity measure. 'torrenthash' field is used to protect
16 -- the integrity of the torrent file created by the publisher, from fake-
17 -- tracker attack, by including sha1 hash of the dictionary corresponding
18 -- to the entire torrent.
20 -- 'InvertedIndex' table is used for precise keyword matching than
21 -- substring search that was used previously.
23 BEGIN TRANSACTION create_table;
25 ----------------------------------------
27 CREATE TABLE BarterCast (
36 CREATE UNIQUE INDEX bartercast_idx
38 (peer_id_from, peer_id_to);
40 ----------------------------------------
42 CREATE TABLE Category (
43 category_id integer PRIMARY KEY NOT NULL,
48 ----------------------------------------
55 ----------------------------------------
57 CREATE TABLE MyPreference (
58 torrent_id integer PRIMARY KEY NOT NULL,
59 destination_path text NOT NULL,
61 creation_time integer NOT NULL,
62 -- V2: Patch for BuddyCast 4
63 click_position INTEGER DEFAULT -1,
64 reranking_strategy INTEGER DEFAULT -1
67 ----------------------------------------
70 peer_id integer PRIMARY KEY AUTOINCREMENT NOT NULL,
77 similarity numeric DEFAULT 0,
78 friend integer DEFAULT 0,
79 superpeer integer DEFAULT 0,
80 last_seen numeric DEFAULT 0,
81 last_connected numeric,
82 last_buddycast numeric,
83 connected_times integer DEFAULT 0,
84 buddycast_times integer DEFAULT 0,
89 -- V3: Addition for local peer discovery
90 is_local integer DEFAULT 0
93 CREATE UNIQUE INDEX permid_idx
97 CREATE INDEX Peer_name_idx
101 CREATE INDEX Peer_ip_idx
105 CREATE INDEX Peer_similarity_idx
109 CREATE INDEX Peer_last_seen_idx
113 CREATE INDEX Peer_last_connected_idx
117 CREATE INDEX Peer_num_peers_idx
121 CREATE INDEX Peer_num_torrents_idx
125 ----------------------------------------
127 CREATE TABLE Preference (
128 peer_id integer NOT NULL,
129 torrent_id integer NOT NULL,
130 -- V2: Patch for BuddyCast 4
131 click_position INTEGER DEFAULT -1,
132 reranking_strategy INTEGER DEFAULT -1
135 CREATE INDEX Preference_peer_id_idx
139 CREATE INDEX Preference_torrent_id_idx
143 CREATE UNIQUE INDEX pref_idx
145 (peer_id, torrent_id);
147 ----------------------------------------
149 CREATE TABLE Torrent (
150 torrent_id integer PRIMARY KEY AUTOINCREMENT NOT NULL,
151 infohash text NOT NULL,
153 torrent_file_name text,
155 creation_date integer,
160 relevance numeric DEFAULT 0,
165 num_leechers integer,
169 CREATE UNIQUE INDEX infohash_idx
173 CREATE INDEX Torrent_length_idx
177 CREATE INDEX Torrent_creation_date_idx
181 CREATE INDEX Torrent_relevance_idx
185 CREATE INDEX Torrent_num_seeders_idx
189 CREATE INDEX Torrent_num_leechers_idx
193 CREATE INDEX Torrent_name_idx
197 ----------------------------------------
199 CREATE TABLE TorrentSource (
200 source_id integer PRIMARY KEY NOT NULL,
205 CREATE UNIQUE INDEX torrent_source_idx
209 ----------------------------------------
211 CREATE TABLE TorrentStatus (
212 status_id integer PRIMARY KEY NOT NULL,
217 ----------------------------------------
219 CREATE TABLE TorrentTracker (
220 torrent_id integer NOT NULL,
221 tracker text NOT NULL,
222 announce_tier integer,
223 ignored_times integer,
224 retried_times integer,
228 CREATE UNIQUE INDEX torrent_tracker_idx
230 (torrent_id, tracker);
232 ----------------------------------------
234 CREATE VIEW SuperPeer AS SELECT * FROM Peer WHERE superpeer=1;
236 CREATE VIEW Friend AS SELECT * FROM Peer WHERE friend=1;
238 CREATE VIEW CollectedTorrent AS SELECT * FROM Torrent WHERE torrent_file_name IS NOT NULL;
241 -- V2: Patch for VoteCast
243 CREATE TABLE VoteCast (
250 CREATE INDEX mod_id_idx
254 CREATE INDEX voter_id_idx
258 CREATE UNIQUE INDEX votecast_idx
263 -- V2: Patch for BuddyCast 4
265 CREATE TABLE ClicklogSearch (
266 peer_id INTEGER DEFAULT 0,
267 torrent_id INTEGER DEFAULT 0,
268 term_id INTEGER DEFAULT 0,
269 term_order INTEGER DEFAULT 0
271 CREATE INDEX idx_search_term ON ClicklogSearch (term_id);
272 CREATE INDEX idx_search_torrent ON ClicklogSearch (torrent_id);
274 CREATE TABLE ClicklogTerm (
275 term_id INTEGER PRIMARY KEY AUTOINCREMENT DEFAULT 0,
276 term VARCHAR(255) NOT NULL,
277 times_seen INTEGER DEFAULT 0 NOT NULL
279 CREATE INDEX idx_terms_term ON ClicklogTerm(term);
285 --v4: Path for BuddyCast 5. Adding Popularity table
287 CREATE TABLE Popularity (
290 msg_receive_time NUMERIC,
291 size_calc_age NUMERIC,
292 num_seeders INTEGER DEFAULT 0,
293 num_leechers INTEGER DEFAULT 0,
294 num_of_sources INTEGER DEFAULT 0
297 CREATE INDEX Message_receive_time_idx
301 CREATE INDEX Size_calc_age_idx
305 CREATE INDEX Number_of_seeders_idx
309 CREATE INDEX Number_of_leechers_idx
313 CREATE UNIQUE INDEX Popularity_idx
315 (torrent_id, peer_id, msg_receive_time);
319 -- v4: Patch for ChannelCast, Search
321 CREATE TABLE ChannelCast (
331 CREATE INDEX pub_id_idx
335 CREATE INDEX pub_name_idx
339 CREATE INDEX infohash_ch_idx
343 ----------------------------------------
345 CREATE TABLE InvertedIndex (
350 CREATE INDEX word_idx
354 CREATE UNIQUE INDEX invertedindex_idx
357 --------------------------------------
360 CREATE TABLE Metadata (
361 metadata_id integer PRIMARY KEY ASC AUTOINCREMENT NOT NULL,
362 publisher_id text NOT NULL,
363 infohash text NOT NULL,
365 timestamp integer NOT NULL,
366 signature text NOT NULL,
367 UNIQUE (publisher_id, infohash),
368 FOREIGN KEY (publisher_id, infohash)
369 REFERENCES ChannelCast(publisher_id, infohash)
370 ON DELETE CASCADE -- the fk constraint is not enforced by sqlite
373 CREATE INDEX infohash_md_idx
374 on Metadata(infohash);
376 CREATE INDEX pub_md_idx
377 on Metadata(publisher_id);
380 CREATE TABLE Subtitles (
381 metadata_id_fk integer,
382 subtitle_lang text NOT NULL,
383 subtitle_location text,
384 checksum text NOT NULL,
385 UNIQUE (metadata_id_fk,subtitle_lang),
386 FOREIGN KEY (metadata_id_fk)
387 REFERENCES Metadata(metadata_id)
388 ON DELETE CASCADE, -- the fk constraint is not enforced by sqlite
390 -- ISO639-2 uses 3 characters for lang codes
391 CONSTRAINT lang_code_length
392 CHECK ( length(subtitle_lang) == 3 )
396 CREATE INDEX metadata_sub_idx
397 on Subtitles(metadata_id_fk);
399 -- Stores the subtitles that peers have as an integer bitmask
400 CREATE TABLE SubtitlesHave (
401 metadata_id_fk integer,
402 peer_id text NOT NULL,
403 have_mask integer NOT NULL,
404 received_ts integer NOT NULL, --timestamp indicating when the mask was received
405 UNIQUE (metadata_id_fk, peer_id),
406 FOREIGN KEY (metadata_id_fk)
407 REFERENCES Metadata(metadata_id)
408 ON DELETE CASCADE, -- the fk constraint is not enforced by sqlite
410 -- 32 bit unsigned integer
411 CONSTRAINT have_mask_length
412 CHECK (have_mask >= 0 AND have_mask < 4294967296)
415 CREATE INDEX subtitles_have_idx
416 on SubtitlesHave(metadata_id_fk);
418 -- this index can boost queries
419 -- ordered by timestamp on the SubtitlesHave DB
420 CREATE INDEX subtitles_have_ts
421 on SubtitlesHave(received_ts);
423 -------------------------------------
425 COMMIT TRANSACTION create_table;
427 ----------------------------------------
429 BEGIN TRANSACTION init_values;
431 INSERT INTO Category VALUES (1, 'Video', 'Video Files');
432 INSERT INTO Category VALUES (2, 'VideoClips', 'Video Clips');
433 INSERT INTO Category VALUES (3, 'Audio', 'Audio');
434 INSERT INTO Category VALUES (4, 'Compressed', 'Compressed');
435 INSERT INTO Category VALUES (5, 'Document', 'Documents');
436 INSERT INTO Category VALUES (6, 'Picture', 'Pictures');
437 INSERT INTO Category VALUES (7, 'xxx', 'XXX');
438 INSERT INTO Category VALUES (8, 'other', 'Other');
440 INSERT INTO TorrentStatus VALUES (0, 'unknown', NULL);
441 INSERT INTO TorrentStatus VALUES (1, 'good', NULL);
442 INSERT INTO TorrentStatus VALUES (2, 'dead', NULL);
444 INSERT INTO TorrentSource VALUES (0, '', 'Unknown');
445 INSERT INTO TorrentSource VALUES (1, 'BC', 'Received from other user');
447 INSERT INTO MyInfo VALUES ('version', 5);
449 COMMIT TRANSACTION init_values;