-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_database.py
More file actions
57 lines (46 loc) · 2 KB
/
test_database.py
File metadata and controls
57 lines (46 loc) · 2 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
import sqlite3
import os
import sys
# Add the backend directory to the path to import modules
sys.path.append(os.path.join(os.path.dirname(__file__), 'backend'))
# Database path
DATABASE_PATH = 'backend/core/data/workers.db'
def test_database():
"""Test database connection and data"""
try:
conn = sqlite3.connect(DATABASE_PATH, timeout=30.0)
conn.row_factory = sqlite3.Row
# Test workers table
print("=== WORKERS TABLE ===")
workers = conn.execute('SELECT id, name, status FROM workers ORDER BY name ASC').fetchall()
print(f"Found {len(workers)} workers:")
for worker in workers:
print(f" ID: {worker['id']}, Name: {worker['name']}, Status: {worker['status']}")
# Test employee_schedules table
print("\n=== EMPLOYEE_SCHEDULES TABLE ===")
schedules = conn.execute('SELECT COUNT(*) as count FROM employee_schedules').fetchone()
print(f"Total schedules: {schedules['count']}")
# Test table structure
print("\n=== TABLE STRUCTURE ===")
columns = conn.execute("PRAGMA table_info(employee_schedules)").fetchall()
print("employee_schedules columns:")
for col in columns:
print(f" {col['name']} ({col['type']})")
# Test recent schedules
print("\n=== RECENT SCHEDULES ===")
recent = conn.execute('''
SELECT es.*, w.name as worker_name
FROM employee_schedules es
LEFT JOIN workers w ON es.employee_id = w.id
ORDER BY es.date DESC
LIMIT 5
''').fetchall()
for schedule in recent:
print(f" {schedule['worker_name']} - {schedule['date']} - {schedule['activity_type']} - {schedule['start_time']} to {schedule['end_time']}")
conn.close()
except Exception as e:
print(f"Database error: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
test_database()