-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_schema.py
More file actions
61 lines (51 loc) · 2.04 KB
/
check_schema.py
File metadata and controls
61 lines (51 loc) · 2.04 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
#!/usr/bin/env python3
"""
Check actual database schema
"""
import sys
import os
# Add the src directory to the path
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
from src.db.database import engine
from sqlalchemy import text
def check_schema():
"""Check actual database schema"""
try:
with engine.connect() as connection:
# Check what tables exist
tables_result = connection.execute(text("""
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY table_name;
"""))
print("Tables in database:")
tables = []
for row in tables_result:
table_name = row[0]
tables.append(table_name)
print(f" - {table_name}")
print("\n" + "="*60)
# Check columns for each table
for table in tables:
print(f"\n Columns in '{table}' table:")
columns_result = connection.execute(text(f"""
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = '{table}'
AND table_schema = 'public'
ORDER BY ordinal_position;
"""))
for row in columns_result:
col_name, data_type, nullable = row
print(f" - {col_name}: {data_type} ({'nullable' if nullable == 'YES' else 'not null'})")
# Check row count
count_result = connection.execute(text(f"SELECT COUNT(*) FROM {table};"))
count = count_result.fetchone()[0]
print(f" 📈 Rows: {count:,}")
except Exception as e:
print(f"Error checking schema: {e}")
if __name__ == "__main__":
print("Checking actual database schema...")
print("=" * 60)
check_schema()