Spaces:
Build error
Build error
| #!/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()) | |