From f9636f86504b5f1d84e51c446909cd1d42e75ff7 Mon Sep 17 00:00:00 2001 From: Oscar Cao Date: Thu, 23 Jan 2025 22:41:45 +0000 Subject: [PATCH] updated database creating more tables --- .gitignore | 2 - web_server/database/app.db | Bin 0 -> 45056 bytes web_server/database/schema.sql | 72 ++++++++++++++++++++++++--------- 3 files changed, 53 insertions(+), 21 deletions(-) create mode 100644 web_server/database/app.db diff --git a/.gitignore b/.gitignore index 3766ec7..5e396ef 100644 --- a/.gitignore +++ b/.gitignore @@ -57,8 +57,6 @@ hls/ sockets/ dev-env/ project_structure.txt -*.db -flask_session/ #Env .env diff --git a/web_server/database/app.db b/web_server/database/app.db new file mode 100644 index 0000000000000000000000000000000000000000..8228aa126625832c2fcab4ad69ac59d6727f58e4 GIT binary patch literal 45056 zcmeI*U2oe|7zc2B?c&yHVK<#6s?rk>kf zpet3sESN%oAU z!NRZWM|FMAP-_=AKUcI$MZP!>0Vg9TOR7M|wMSOm9#XBtcH=;ApM(MG$5yLhvTYm~ zrZvSkv+2E-CF9T*2eB9ing{Uztf`wdu{t&_FNJVhPA{g8?a>CuV{Wo zPCYuxUz=tjjX}(Kym?|7Kd?d&iotgVwBymCpOIl~_P(RP8GG;#C@%uDu67hU{27CkkE@Dk=)WqLXMhJog{#c&oyk=uiujG~dFSq^$6bi- zPxqk%+v%qr?%$hUA0#I_!?V(pB;}Chm=5WP_Wm(7FB~^46LxL|=gW=Y1rG>700Izz z00bZa0SG_<0uX=z1d1xa-TyCs_-9e0L|hPn00bZa0SG_<0uX=z1Rwx`;tMPR+PM4w;zJ-p2tWV=5P$##AOHafKmY;|fWVvz;QoJ36OXVV009U< z00Izz00bZa0SG`~t^{!ZKUe8Sun>R%1Rwwb2tWV=5P$##ATXx_Y7lqy_y0u;f8%9I7UjP6A literal 0 HcmV?d00001 diff --git a/web_server/database/schema.sql b/web_server/database/schema.sql index 728cd07..178bfe2 100644 --- a/web_server/database/schema.sql +++ b/web_server/database/schema.sql @@ -1,13 +1,13 @@ DROP TABLE IF EXISTS users; CREATE TABLE users ( + user_id INTEGER PRIMARY KEY AUTOINCREMENT, username VARCHAR(50) NOT NULL, password VARCHAR(256) NOT NULL, email VARCHAR(64) NOT NULL, num_followers INTEGER NOT NULL, isPartenered BOOLEAN NOT NULL DEFAULT 0, - bio TEXT, - PRIMARY KEY (username) + bio TEXT ); SELECT * FROM users; @@ -16,36 +16,70 @@ SELECT * FROM users; DROP TABLE IF EXISTS streams; CREATE TABLE streams ( - stream_id INTEGER AUTOINCREMENT, + stream_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT NOT NULL, start_time DATETIME NOT NULL, - num_viewers INT NOT NULL DEFAULT 0, + num_viewers INTEGER NOT NULL DEFAULT 0, isLive BOOLEAN NOT NULL DEFAULT 0, - vod_id INT, - streamer_id VARCHAR NOT NULL, - PRIMARY KEY (stream_id), - FOREIGN KEY (streamer_id) REFERENCES users(username) ON DELETE CASCADE + vod_id INTEGER, + streamer_id INTEGER NOT NULL, + FOREIGN KEY (streamer_id) REFERENCES streamers(user_id) ON DELETE CASCADE ); +DROP TABLE IF EXISTS streamers; +CREATE TABLE streamers +( + user_id INTEGER PRIMARY KEY NOT NULL, + streamer_id INTEGER NOT NULL, + FOREIGN KEY(user_id) REFERENCES users(user_id) ON DELETE CASCADE +); + + DROP TABLE IF EXISTS follows; CREATE TABLE follows ( - username VARCHAR(50) NOT NULL, - following_id VARCHAR(50) NOT NULL, - PRIMARY KEY (username, following_id), - FOREIGN KEY (username) REFERENCES users(username) ON DELETE CASCADE, - FOREIGN KEY (following_id) REFERENCES users(username) ON DELETE CASCADE + user_id INTEGER NOT NULL, + streamer_id INTEGER NOT NULL, + PRIMARY KEY (user_id, streamer_id), + FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE, + FOREIGN KEY (streamer_id) REFERENCES streamers(streamer_id) ON DELETE CASCADE ); DROP TABLE IF EXISTS chat; CREATE TABLE chat ( - message_id INT AUTOINCREMENT, - chatter_id VARCHAR(50) NOT NULL, - stream_id INT NOT NULL, + message_id INTEGER NOT NULL, + user_id INTEGER NOT NULL, + stream_id INTEGER NOT NULL, message TEXT NOT NULL, time_sent DATETIME NOT NULL, - PRIMARY KEY (message_id), - FOREIGN KEY (chatter_id) REFERENCES users(username), + PRIMARY KEY (message_id, stream_id), + FOREIGN KEY (user_id) REFERENCES users(user_id), FOREIGN KEY (stream_id) REFERENCES streams(stream_id) ON DELETE CASCADE -); \ No newline at end of file +); + +DROP TABLE IF EXISTS categories; +CREATE TABLE categories +( + category_id INTEGER PRIMARY KEY AUTOINCREMENT, + category_name VARCHAR(25) NOT NULL +); + +DROP TABLE IF EXISTS stream_categories; +CREATE TABLE stream_categories +( + stream_id INTEGER NOT NULL, + category_id INTEGER NOT NULL, + since DATETIME NOT NULL, + FOREIGN KEY (stream_id) REFERENCES streams(stream_id), + FOREIGN KEY (category_id) REFERENCES categories(category_id) ON DELETE CASCADE +); + +DROP TABLE IF EXISTS user_preferences; +CREATE TABLE user_preferences +( + user_id INT NOT NULL, + category_id INT NOT NULL, + favourability INT NOT NULL DEFAULT 0, + PRIMARY KEY(user_id, category_id) +) \ No newline at end of file