-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_setup.py
More file actions
36 lines (31 loc) · 878 Bytes
/
db_setup.py
File metadata and controls
36 lines (31 loc) · 878 Bytes
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
import sqlite3
# Connect or create the database file
conn = sqlite3.connect("database.db")
cursor = conn.cursor()
# Create the 'users' table
cursor.execute("""
CREATE TABLE IF NOT EXISTS users (
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL,
password TEXT NOT NULL,
role TEXT NOT NULL CHECK(role IN ('Employee', 'Admin'))
);
""")
# Create the 'tickets' table
cursor.execute("""
CREATE TABLE IF NOT EXISTS tickets (
ticket_id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
category TEXT,
description TEXT,
status TEXT DEFAULT 'Open',
assigned_to TEXT,
priority TEXT DEFAULT 'Medium',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users (user_id)
);
""")
print("✅ Database and tables created successfully!")
conn.commit()
conn.close()