Moved frontend out of webserver into it's own container
This commit is contained in:
22
web_server/database/database.py
Normal file
22
web_server/database/database.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
class Database:
|
||||
def __init__(self) -> None:
|
||||
self._db = os.path.join(os.path.abspath(os.path.dirname(__file__)), "app.db")
|
||||
|
||||
def create_connection(self) -> sqlite3.Cursor:
|
||||
conn = sqlite3.connect(self._db)
|
||||
conn.row_factory = sqlite3.Row
|
||||
self._conn = conn
|
||||
cursor = conn.cursor()
|
||||
return cursor
|
||||
|
||||
def commit_data(self):
|
||||
try:
|
||||
self._conn.commit()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
def close_connection(self) -> None:
|
||||
self._conn.close()
|
||||
36
web_server/database/schema.sql
Normal file
36
web_server/database/schema.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
DROP TABLE IF EXISTS users;
|
||||
CREATE TABLE users
|
||||
(
|
||||
username VARCHAR(50) PRIMARY KEY 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
|
||||
);
|
||||
|
||||
SELECT * FROM users;
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS streams;
|
||||
CREATE TABLE streams
|
||||
(
|
||||
stream_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
start_time DATETIME NOT NULL,
|
||||
num_viewers INT NOT NULL DEFAULT 0,
|
||||
isLive BOOLEAN NOT NULL DEFAULT 0,
|
||||
vod_id INT,
|
||||
streamer_id VARCHAR NOT NULL,
|
||||
FOREIGN KEY (streamer_id) REFERENCES users(username) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
DROP TABLE IF EXISTS follows;
|
||||
CREATE TABLE follows
|
||||
(
|
||||
user_id INT NOT NULL,
|
||||
following_id INT NOT NULL,
|
||||
PRIMARY KEY (user_id, following_id),
|
||||
FOREIGN KEY (user_id) REFERENCES users(username) ON DELETE CASCADE,
|
||||
FOREIGN KEY (following_id) REFERENCES users(username) ON DELETE CASCADE
|
||||
);
|
||||
Reference in New Issue
Block a user