updated database creating more tables

This commit is contained in:
Oscar Cao
2025-01-23 22:41:45 +00:00
parent 667088ec9e
commit f9636f8650
3 changed files with 53 additions and 21 deletions

2
.gitignore vendored
View File

@@ -57,8 +57,6 @@ hls/
sockets/ sockets/
dev-env/ dev-env/
project_structure.txt project_structure.txt
*.db
flask_session/
#Env #Env
.env .env

BIN
web_server/database/app.db Normal file

Binary file not shown.

View File

@@ -1,13 +1,13 @@
DROP TABLE IF EXISTS users; DROP TABLE IF EXISTS users;
CREATE TABLE users CREATE TABLE users
( (
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
username VARCHAR(50) NOT NULL, username VARCHAR(50) NOT NULL,
password VARCHAR(256) NOT NULL, password VARCHAR(256) NOT NULL,
email VARCHAR(64) NOT NULL, email VARCHAR(64) NOT NULL,
num_followers INTEGER NOT NULL, num_followers INTEGER NOT NULL,
isPartenered BOOLEAN NOT NULL DEFAULT 0, isPartenered BOOLEAN NOT NULL DEFAULT 0,
bio TEXT, bio TEXT
PRIMARY KEY (username)
); );
SELECT * FROM users; SELECT * FROM users;
@@ -16,36 +16,70 @@ SELECT * FROM users;
DROP TABLE IF EXISTS streams; DROP TABLE IF EXISTS streams;
CREATE TABLE streams CREATE TABLE streams
( (
stream_id INTEGER AUTOINCREMENT, stream_id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL, title TEXT NOT NULL,
start_time DATETIME 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, isLive BOOLEAN NOT NULL DEFAULT 0,
vod_id INT, vod_id INTEGER,
streamer_id VARCHAR NOT NULL, streamer_id INTEGER NOT NULL,
PRIMARY KEY (stream_id), FOREIGN KEY (streamer_id) REFERENCES streamers(user_id) ON DELETE CASCADE
FOREIGN KEY (streamer_id) REFERENCES users(username) 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; DROP TABLE IF EXISTS follows;
CREATE TABLE follows CREATE TABLE follows
( (
username VARCHAR(50) NOT NULL, user_id INTEGER NOT NULL,
following_id VARCHAR(50) NOT NULL, streamer_id INTEGER NOT NULL,
PRIMARY KEY (username, following_id), PRIMARY KEY (user_id, streamer_id),
FOREIGN KEY (username) REFERENCES users(username) ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE,
FOREIGN KEY (following_id) REFERENCES users(username) ON DELETE CASCADE FOREIGN KEY (streamer_id) REFERENCES streamers(streamer_id) ON DELETE CASCADE
); );
DROP TABLE IF EXISTS chat; DROP TABLE IF EXISTS chat;
CREATE TABLE chat CREATE TABLE chat
( (
message_id INT AUTOINCREMENT, message_id INTEGER NOT NULL,
chatter_id VARCHAR(50) NOT NULL, user_id INTEGER NOT NULL,
stream_id INT NOT NULL, stream_id INTEGER NOT NULL,
message TEXT NOT NULL, message TEXT NOT NULL,
time_sent DATETIME NOT NULL, time_sent DATETIME NOT NULL,
PRIMARY KEY (message_id), PRIMARY KEY (message_id, stream_id),
FOREIGN KEY (chatter_id) REFERENCES users(username), FOREIGN KEY (user_id) REFERENCES users(user_id),
FOREIGN KEY (stream_id) REFERENCES streams(stream_id) ON DELETE CASCADE FOREIGN KEY (stream_id) REFERENCES streams(stream_id) ON DELETE CASCADE
); );
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)
)