File size: 1,477 Bytes
09fa60b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Test database connection and generation creation."""

import asyncio
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent))

from app.db.database import AsyncSessionLocal
from app.db.models import Generation
from app.core.config import settings

async def test_db():
    """Test database connection and create a test generation."""
    print(f"Testing database connection to: {settings.DATABASE_URL}")
    
    try:
        async with AsyncSessionLocal() as db:
            # Test connection
            from sqlalchemy import text
            result = await db.execute(text("SELECT 1"))
            print("✅ Database connection successful")
            
            # Try to create a test generation
            test_gen = Generation(
                prompt="Test prompt",
                duration=10,
                status="pending"
            )
            db.add(test_gen)
            await db.commit()
            await db.refresh(test_gen)
            print(f"✅ Test generation created: {test_gen.id}")
            
            # Clean up
            await db.delete(test_gen)
            await db.commit()
            print("✅ Test generation cleaned up")
            
    except Exception as e:
        print(f"❌ Error: {e}")
        import traceback
        traceback.print_exc()
        sys.exit(1)

if __name__ == "__main__":
    asyncio.run(test_db())