-
Notifications
You must be signed in to change notification settings - Fork 0
/
initializedb.py
69 lines (62 loc) · 1.9 KB
/
initializedb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sqlite3
def initialize_database():
conn = sqlite3.connect('app_database.db')
cursor = conn.cursor()
# Create Users table
cursor.execute('''
CREATE TABLE IF NOT EXISTS Users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
email TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
# Create ProfilePictures table
cursor.execute('''
CREATE TABLE IF NOT EXISTS ProfilePictures (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
image BLOB,
uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(user_id) REFERENCES Users(id) ON DELETE CASCADE
)
''')
# Create SearchHistory table
cursor.execute('''
CREATE TABLE IF NOT EXISTS SearchHistory (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
query TEXT,
search_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(user_id) REFERENCES Users(id) ON DELETE CASCADE
)
''')
# Create DataRequests table
cursor.execute('''
CREATE TABLE IF NOT EXISTS DataRequests (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
data_type TEXT,
symbol TEXT,
indicator TEXT,
currency_pair TEXT,
start_date DATE,
end_date DATE,
provider TEXT,
request_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(user_id) REFERENCES Users(id) ON DELETE CASCADE
)
''')
# Create Favorites table
cursor.execute('''
CREATE TABLE IF NOT EXISTS Favorites (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
symbol TEXT,
added_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(user_id) REFERENCES Users(id) ON DELETE CASCADE
)
''')
conn.commit()
conn.close()