This repository was archived by the owner on Jan 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
37 lines (29 loc) · 1.31 KB
/
database.py
File metadata and controls
37 lines (29 loc) · 1.31 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
from FlaskAPIServer.utils.database import SQL_request
ROLES = {"user":10, "admin":20}
SQL_request("""CREATE TABLE IF NOT EXISTS groups (
id INTEGER PRIMARY KEY AUTOINCREMENT,
group_name VARCHAR(255) NOT NULL,
link TEXT,
complex_name TEXT,
course INTEGER NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
time_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status TEXT DEFAULT 'active'
);""")
def create_group(group):
SQL_request(f"""CREATE TABLE IF NOT EXISTS {group} (
week_id INTEGER,
timetable JSON,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
time_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status TEXT DEFAULT 'active'
);""")
def delete_group(group):
SQL_request(f"""DROP TABLE IF EXISTS {group};""")
SQL_request("UPDATE key_roles SET priority=? WHERE name=?;", (50, "api_key"), None)
existing_roles = SQL_request(query="SELECT name FROM key_roles;", fetch='all')
existing_names = [role['name'] for role in existing_roles] if existing_roles else []
roles_to_insert = [(name, priority) for name, priority in ROLES.items() if name not in existing_names]
if roles_to_insert:
for name, priority in roles_to_insert:
SQL_request(query="INSERT INTO key_roles (name, priority) VALUES (?, ?);", params=(name, priority), fetch=None)