-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_db_schema.py
More file actions
64 lines (51 loc) · 2.17 KB
/
Copy pathcheck_db_schema.py
File metadata and controls
64 lines (51 loc) · 2.17 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
#!/usr/bin/env python3
"""Verify database schema created by Alembic migrations."""
import sqlite3
from pathlib import Path
def main():
"""Verify database schema."""
db_path = Path("data/shopmind.db")
if not db_path.exists():
print("❌ Database file not found")
return
conn = sqlite3.connect(str(db_path))
cursor = conn.cursor()
# Get all tables
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;")
tables = [row[0] for row in cursor.fetchall()]
print("📊 Database Schema Verification\n")
print(f"✅ Database: {db_path}")
print(f"✅ Tables: {', '.join(tables)}\n")
# Check diagnostic_sessions
print("📍 diagnostic_sessions table:")
cursor.execute("PRAGMA table_info(diagnostic_sessions);")
columns = cursor.fetchall()
torch_cols = {'torch_predictions', 'predicted_causes', 'training_ready', 'confirmed_cause'}
found_torch = set()
for col_id, name, col_type, notnull, dflt, pk in columns:
marker = "⭐" if name in torch_cols else " "
print(f"{marker} {name}: {col_type}")
if name in torch_cols:
found_torch.add(name)
# Check indexes
cursor.execute("SELECT name FROM sqlite_master WHERE type='index' AND tbl_name='diagnostic_sessions';")
indexes = [row[0] for row in cursor.fetchall()]
print(f"\n✅ Indexes: {len(indexes)} created on diagnostic_sessions")
# Check root_causes
cursor.execute("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='root_causes';")
if cursor.fetchone()[0]:
print("✅ root_causes table: present")
# Check alembic_version
cursor.execute("SELECT version_num FROM alembic_version;")
version = cursor.fetchone()
print(f"\n✅ Migration Status: {version[0] if version else 'None'}")
# Verify Torch fields
missing_torch = torch_cols - found_torch
if not missing_torch:
print("✅ All Torch ML fields present!")
else:
print(f"❌ Missing Torch fields: {missing_torch}")
conn.close()
print("\n✅ Database schema verification complete!")
if __name__ == "__main__":
main()