| """ |
| Debug Database Connection Issues |
| """ |
|
|
| import asyncio |
| import sys |
| from pathlib import Path |
| import logging |
| from urllib.parse import quote_plus |
|
|
| |
| backend_path = Path(__file__).parent |
| sys.path.insert(0, str(backend_path)) |
|
|
| from core.config import settings |
|
|
| logging.basicConfig(level=logging.INFO) |
| logger = logging.getLogger(__name__) |
|
|
| def debug_database_url(): |
| """Debug and fix database URL""" |
| |
| original_url = settings.DATABASE_URL |
| logger.info(f"🔍 Original DATABASE_URL: {original_url}") |
| |
| |
| if "postgres:@" in original_url and original_url.count("@") > 2: |
| logger.error("❌ Issue detected: Missing password in database URL") |
| logger.error("❌ Format should be: postgresql+asyncpg://postgres:PASSWORD@host:port/db") |
| |
| |
| parts = original_url.split("@") |
| logger.info(f"📋 URL parts: {parts}") |
| |
| |
| |
| |
| |
| return False |
| |
| return True |
|
|
| def suggest_fix(): |
| """Suggest how to fix the database URL""" |
| |
| logger.info("🔧 SUGGESTED FIXES:") |
| logger.info("1. Get the actual Supabase database password") |
| logger.info("2. URL-encode special characters in password") |
| logger.info("3. Update DATABASE_URL with correct format") |
| |
| |
| example_password = "@Jk=54##0@@6@1@" |
| encoded_password = quote_plus(example_password) |
| |
| logger.info(f"📝 Example encoding:") |
| logger.info(f" Original: {example_password}") |
| logger.info(f" Encoded: {encoded_password}") |
| |
| |
| corrected_url = f"postgresql+asyncpg://postgres:{encoded_password}@db.txtxywmflduurfhfhnlu.supabase.co:5432/postgres" |
| logger.info(f"🔧 Corrected URL example: {corrected_url}") |
|
|
| if __name__ == "__main__": |
| logger.info("🚀 Database Connection Debug") |
| |
| if debug_database_url(): |
| logger.info("✅ Database URL format looks correct") |
| else: |
| logger.info("❌ Database URL has issues") |
| suggest_fix() |
|
|