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/
dev-env/
project_structure.txt
*.db
flask_session/
#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;
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
);
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)
)