@@ -4,6 +4,7 @@ CREATE TABLE users (
44 platform VARCHAR (10 ) NOT NULL ,
55 bio VARCHAR (260 )
66);
7+
78CREATE TABLE repos (
89 -- The username is 40 characters at max, repo name is 100 and the key and slashes is 5
910 -- Hence, I can keep this at 150.
@@ -24,15 +25,9 @@ CREATE TABLE repos (
2425 created_at TIMESTAMP NOT NULL ,
2526 -- I just realised that the boolean type is like an integer only.
2627 -- I added check that it should only be either true or false. i.e 0, 1
27- is_archived BOOLEAN NOT NULL CHECK (
28- is_archived IN (0 , 1 )
29- ),
30- is_disabled BOOLEAN NOT NULL CHECK (
31- is_disabled IN (0 , 1 )
32- ),
33- is_fork BOOLEAN NOT NULL CHECK (
34- is_fork IN (0 , 1 )
35- ),
28+ is_archived BOOLEAN NOT NULL CHECK (is_archived IN (0 , 1 )),
29+ is_disabled BOOLEAN NOT NULL CHECK (is_disabled IN (0 , 1 )),
30+ is_fork BOOLEAN NOT NULL CHECK (is_fork IN (0 , 1 )),
3631 -- Making this only 30 characters limit, it shouldn't be more than that.
3732 -- Simple google tells, its just 36 characters, so, ok?
3833 license VARCHAR (40 ) NOT NULL ,
@@ -42,9 +37,9 @@ CREATE TABLE repos (
4237 last_updated_in_this_database TIMESTAMP NOT NULL ,
4338 FOREIGN KEY (owner) REFERENCES users (id) ON DELETE CASCADE
4439);
45- CREATE VIRTUAL TABLE repo_search USING fts5 (
46- repo_id, keywords, tokenize = ' porter'
47- );
40+
41+ CREATE VIRTUAL TABLE repo_search USING fts5 ( repo_id, keywords, tokenize = ' porter' );
42+
4843-- Doing this to make sure, no duplicate repo_id is added.
4944-- I will be using this query:
5045-- INSERT OR REPLACE INTO repo_search (repo_id, keywords) VALUES (?, ?)
@@ -55,12 +50,14 @@ CREATE TABLE repo_topics (
5550 FOREIGN KEY (repo_id) REFERENCES repos (id) ON DELETE CASCADE ,
5651 UNIQUE (repo_id, topic)
5752);
53+
5854CREATE TABLE repo_dependents (
5955 repo_id VARCHAR (150 ) NOT NULL ,
6056 dependent VARCHAR (260 ) NOT NULL ,
6157 FOREIGN KEY (repo_id) REFERENCES repos (id) ON DELETE CASCADE ,
6258 UNIQUE (repo_id, dependent)
6359);
60+
6461CREATE TABLE releases (
6562 id INTEGER PRIMARY KEY AUTOINCREMENT,
6663 repo_id VARCHAR (150 ) NOT NULL ,
@@ -74,32 +71,35 @@ CREATE TABLE releases (
7471 FOREIGN KEY (repo_id) REFERENCES repos (id) ON DELETE CASCADE ,
7572 UNIQUE (repo_id, version)
7673);
74+
7775CREATE TABLE release_dependencies (
7876 release_id INTEGER NOT NULL ,
7977 name VARCHAR (260 ) NOT NULL ,
8078 hash VARCHAR (260 ) NOT NULL ,
81- is_lazy BOOLEAN NOT NULL CHECK (
82- is_lazy IN (0 , 1 )
83- ),
79+ is_lazy BOOLEAN NOT NULL CHECK (is_lazy IN (0 , 1 )),
8480 url VARCHAR (260 ) NOT NULL ,
8581 path VARCHAR (260 ) NOT NULL ,
8682 FOREIGN KEY (release_id) REFERENCES releases (id) ON DELETE CASCADE ,
8783 UNIQUE (release_id, name)
8884);
85+
8986CREATE TABLE index_sections (
9087 section_name VARCHAR (10 ) NOT NULL ,
9188 repo_id VARCHAR (150 ) NOT NULL ,
9289 FOREIGN KEY (repo_id) REFERENCES repos (id) ON DELETE CASCADE ,
9390 UNIQUE (section_name, repo_id)
9491);
92+
9593CREATE TABLE packages (
9694 repo_id VARCHAR (150 ) NOT NULL PRIMARY KEY ,
9795 FOREIGN KEY (repo_id) REFERENCES repos (id) ON DELETE CASCADE
9896);
97+
9998CREATE TABLE programs (
10099 repo_id VARCHAR (150 ) NOT NULL PRIMARY KEY ,
101100 FOREIGN KEY (repo_id) REFERENCES repos (id) ON DELETE CASCADE
102101);
102+
103103CREATE TABLE index_new_repo (
104104 id VARCHAR (150 ) PRIMARY KEY ,
105105 type_of_repo VARCHAR (10 ) NOT NULL -- This is like, package or program.
@@ -109,44 +109,51 @@ CREATE TABLE safe_to_index_new_repo (
109109 id VARCHAR (150 ) PRIMARY KEY ,
110110 type_of_repo VARCHAR (10 ) NOT NULL -- This is like, package or program.
111111);
112+
112113-- For this specifically, I will create a AI model, I will train it to detect
113114-- all the scam repos, if my AI algorithm flags a repo
114115-- to review it will be added to this table, if no problem, it will continue.
115116CREATE TABLE quarantined_repos (
116117 id VARCHAR (150 ) PRIMARY KEY ,
117118 type_of_repo VARCHAR (10 ) NOT NULL
118119);
120+
119121-- These are only the users who are either spamming or
120122-- shipping malware.
121- CREATE TABLE banned_user_list (
122- id VARCHAR (45 ) PRIMARY KEY
123- );
123+ CREATE TABLE banned_user_list (id VARCHAR (45 ) PRIMARY KEY );
124+
124125-- This is for making it easier to fetch
125126-- details of these repositories
126127-- to improve the accuracy of the algorithm
127128-- which detects such repos.
128- CREATE TABLE banned_repo_list (
129- id VARCHAR (150 ) PRIMARY KEY
130- );
129+ CREATE TABLE banned_repo_list (id VARCHAR (150 ) PRIMARY KEY );
130+
131131-- Needs update
132132CREATE TABLE needs_updates (
133133 id VARCHAR (150 ) PRIMARY KEY ,
134134 -- All the repos that need updates.
135135 type_of_repo VARCHAR (10 ) NOT NULL -- This is like, package or program.
136- );
136+ );
137+
137138-- I do search for "All repos where username is username"
138139CREATE INDEX repo_owner_index ON repos (owner);
140+
139141-- Again, I do this, specially for the top 10 latest repos
140142CREATE INDEX repo_created_at_index ON repos (created_at);
143+
141144-- again, for repos with most stars
142145CREATE INDEX repo_star_count_index ON repos (stargazer_count);
146+
143147-- Whenever someone visits a repo page, that page
144148-- needs "ALl the releases with of that repo."
145149CREATE INDEX releases_repo_index ON releases (repo_id, published_at DESC );
150+
146151-- Also, for every release, I need to get
147152-- all the dependencies of that release
148153CREATE INDEX release_dependencies_release_id_index ON release_dependencies (release_id);
154+
149155-- Ok, on every package I also need number of repo topics.
150156CREATE INDEX repo_topics_repo_id_index ON repo_topics (repo_id);
157+
151158-- Ok, on every package I also need number of repo dependents.
152159CREATE INDEX repo_dependents_repo_id_index ON repo_dependents (repo_id);
0 commit comments