-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
69 lines (57 loc) · 2.11 KB
/
Copy pathdatabase.py
File metadata and controls
69 lines (57 loc) · 2.11 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
64
65
66
67
68
69
import sqlite3
DATABASE_NAME = "tickets.db"
def get_db_connection():
conn = sqlite3.connect(DATABASE_NAME)
conn.row_factory = sqlite3.Row
return conn
def ensure_column(conn, table_name, column_name, column_definition):
existing_columns = {
row["name"]
for row in conn.execute(f"PRAGMA table_info({table_name})").fetchall()
}
if column_name not in existing_columns:
conn.execute(
f"ALTER TABLE {table_name} ADD COLUMN {column_name} {column_definition}"
)
def init_db():
conn = get_db_connection()
#Ticket table
conn.execute("""
CREATE TABLE IF NOT EXISTS tickets (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ticket_type TEXT NOT NULL DEFAULT 'task',
category TEXT NOT NULL DEFAULT 'general_task',
priority TEXT NOT NULL DEFAULT 'normal',
title TEXT NOT NULL,
description TEXT NOT NULL,
reported_by TEXT,
reported_to TEXT,
assigned_to TEXT,
visibility TEXT DEFAULT 'public',
status TEXT DEFAULT 'pending',
proof_required INTEGER DEFAULT 1,
proof_type TEXT DEFAULT 'photo',
proof_path TEXT,
staff_note TEXT,
manager_comment TEXT,
is_demo INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
""")
conn.execute("""
CREATE TABLE IF NOT EXISTS audit_logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ticket_id INTEGER NOT NULL,
action TEXT NOT NULL,
actor TEXT NOT NULL,
details TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (ticket_id) REFERENCES tickets (id)
)
""")
ensure_column(conn, "tickets", "category", "TEXT NOT NULL DEFAULT 'general_task'")
ensure_column(conn, "tickets", "priority", "TEXT NOT NULL DEFAULT 'normal'")
ensure_column(conn, "tickets", "is_demo", "INTEGER DEFAULT 0")
conn.commit()
conn.close()