init commit
This commit is contained in:
50
test_db_connection.py
Normal file
50
test_db_connection.py
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
"""Simple database connectivity test"""
|
||||
import sys
|
||||
from sqlalchemy import create_engine, text
|
||||
from app.core.config import settings
|
||||
|
||||
print("🧪 Testing Database Connection...")
|
||||
print(f" Database URL: {settings.database_url}")
|
||||
|
||||
try:
|
||||
engine = create_engine(settings.database_url)
|
||||
with engine.connect() as conn:
|
||||
# Test 1: Check version
|
||||
result = conn.execute(text("SELECT version();"))
|
||||
version = result.fetchone()[0]
|
||||
print(f"✅ Connected to: {version[:50]}...")
|
||||
|
||||
# Test 2: List tables
|
||||
result = conn.execute(text("""
|
||||
SELECT tablename FROM pg_tables
|
||||
WHERE schemaname = 'public'
|
||||
ORDER BY tablename
|
||||
"""))
|
||||
tables = [row[0] for row in result.fetchall()]
|
||||
print(f"✅ Found {len(tables)} tables:")
|
||||
for table in tables:
|
||||
print(f" - {table}")
|
||||
|
||||
# Test 3: List enum types
|
||||
result = conn.execute(text("""
|
||||
SELECT typname FROM pg_type
|
||||
WHERE typtype='e' AND typname NOT LIKE '%type'
|
||||
ORDER BY typname
|
||||
"""))
|
||||
enums = [row[0] for row in result.fetchall()]
|
||||
print(f"✅ Found {len(enums)} enum types:")
|
||||
for enum in enums:
|
||||
print(f" - {enum}")
|
||||
|
||||
# Test 4: Check data in tables
|
||||
result = conn.execute(text("SELECT COUNT(*) FROM users;"))
|
||||
user_count = result.fetchone()[0]
|
||||
print(f"✅ Users table: {user_count} records")
|
||||
|
||||
print("\n✅ ALL TESTS PASSED!")
|
||||
sys.exit(0)
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ ERROR: {type(e).__name__}: {str(e)}")
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user