File size: 2,230 Bytes
2ed8996
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
65
66
67
68
69
70
71
"""
Debug Database Connection Issues
"""

import asyncio
import sys
from pathlib import Path
import logging
from urllib.parse import quote_plus

# Add backend to path
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}")
    
    # Parse the URL to identify issues
    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")
        
        # Extract components
        parts = original_url.split("@")
        logger.info(f"📋 URL parts: {parts}")
        
        # The issue is that password is missing
        # Current: postgres:@Jk=54##0@@6@1@db...
        # Should be: postgres:PASSWORD@db...
        
        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 of proper URL encoding
    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}")
    
    # Show what the corrected URL should look like
    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()