82 lines
2.8 KiB
Python
Executable File
82 lines
2.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Diagnostic script to check production database tables and data.
|
|
Run this in your production Kubernetes pod to diagnose the issue.
|
|
"""
|
|
|
|
from db_config import db_config, sql_read_static
|
|
from sqlalchemy import text, inspect
|
|
|
|
def check_database():
|
|
"""Check database tables and data"""
|
|
print("=" * 60)
|
|
print("Production Database Diagnostic")
|
|
print("=" * 60)
|
|
print()
|
|
|
|
engine = db_config.engine
|
|
inspector = inspect(engine)
|
|
tables = inspector.get_table_names()
|
|
|
|
print("1. Checking tables...")
|
|
print(f" Total tables: {len(tables)}")
|
|
print(f" Has 'admin_settings': {'admin_settings' in tables}")
|
|
print(f" Has 'motmadminsettings': {'motmadminsettings' in tables}")
|
|
print()
|
|
|
|
# Check admin_settings table
|
|
if 'admin_settings' in tables:
|
|
print("2. Checking 'admin_settings' table...")
|
|
try:
|
|
result = sql_read_static(text("SELECT * FROM admin_settings"))
|
|
print(f" Rows: {len(result)}")
|
|
if result:
|
|
row = result[0]
|
|
print(f" Columns: {list(row.keys())}")
|
|
print(f" userid: {row.get('userid')}")
|
|
print(f" next_date: {row.get('next_date')}")
|
|
print(f" next_club: {row.get('next_club')}")
|
|
print(f" next_team: {row.get('next_team')}")
|
|
print(f" motm_url_suffix: {row.get('motm_url_suffix')}")
|
|
print(f" votingdeadline: {row.get('votingdeadline')}")
|
|
except Exception as e:
|
|
print(f" Error: {e}")
|
|
print()
|
|
|
|
# Check motmadminsettings table
|
|
if 'motmadminsettings' in tables:
|
|
print("3. Checking 'motmadminsettings' table...")
|
|
try:
|
|
result = sql_read_static(text("SELECT * FROM motmadminsettings"))
|
|
print(f" Rows: {len(result)}")
|
|
if result:
|
|
row = result[0]
|
|
print(f" Columns: {list(row.keys())}")
|
|
except Exception as e:
|
|
print(f" Error: {e}")
|
|
print()
|
|
|
|
# Test the specific query that's failing
|
|
print("4. Testing the failing query...")
|
|
try:
|
|
sql5 = text("SELECT motm_url_suffix FROM admin_settings WHERE userid = 'admin'")
|
|
tempSuffix = sql_read_static(sql5)
|
|
print(f" Query result: {tempSuffix}")
|
|
print(f" Result length: {len(tempSuffix) if tempSuffix else 0}")
|
|
if tempSuffix:
|
|
print(f" motm_url_suffix value: {tempSuffix[0].get('motm_url_suffix')}")
|
|
print(f" Is None or empty: {not tempSuffix[0].get('motm_url_suffix')}")
|
|
else:
|
|
print(" ERROR: No results returned!")
|
|
except Exception as e:
|
|
print(f" Error: {e}")
|
|
print()
|
|
|
|
print("=" * 60)
|
|
print("Diagnostic Complete")
|
|
print("=" * 60)
|
|
|
|
if __name__ == "__main__":
|
|
check_database()
|
|
|