-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
63 lines (56 loc) · 1.73 KB
/
database.py
File metadata and controls
63 lines (56 loc) · 1.73 KB
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
import sqlite3
from datetime import datetime
def init_db():
conn = sqlite3.connect('eduledger.db')
cursor = conn.cursor()
# Create Students table
cursor.execute('''
CREATE TABLE IF NOT EXISTS students (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
unique_id TEXT UNIQUE NOT NULL,
email TEXT UNIQUE NOT NULL,
branch TEXT NOT NULL,
year INTEGER NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
# Create Faculty table
cursor.execute('''
CREATE TABLE IF NOT EXISTS faculty (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
unique_id TEXT UNIQUE NOT NULL,
email TEXT UNIQUE NOT NULL,
research_area TEXT,
post TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
# Create Subjects table
cursor.execute('''
CREATE TABLE IF NOT EXISTS subjects (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
code TEXT UNIQUE NOT NULL,
credits INTEGER NOT NULL
)
''')
# Create Faculty-Student Assignments table
cursor.execute('''
CREATE TABLE IF NOT EXISTS faculty_assignments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
student_id INTEGER,
faculty_id INTEGER,
subject_id INTEGER,
start_date DATE NOT NULL,
end_date DATE NOT NULL,
FOREIGN KEY (student_id) REFERENCES students (id),
FOREIGN KEY (faculty_id) REFERENCES faculty (id),
FOREIGN KEY (subject_id) REFERENCES subjects (id)
)
''')
conn.commit()
conn.close()
if __name__ == "__main__":
init_db()