Spaces:
Build error
Build error
| #!/usr/bin/env python3 | |
| """Initialize database with tables.""" | |
| import asyncio | |
| import sys | |
| from pathlib import Path | |
| # Fix Windows console encoding | |
| if sys.platform == "win32": | |
| import io | |
| sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace') | |
| sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace') | |
| # Add parent directory to path | |
| sys.path.insert(0, str(Path(__file__).parent.parent)) | |
| from app.db.database import init_db, engine | |
| from app.db.models import Base | |
| from app.core.logging import configure_logging | |
| import structlog | |
| logger = structlog.get_logger(__name__) | |
| async def main(): | |
| """Initialize database.""" | |
| configure_logging() | |
| logger.info("initializing_database") | |
| try: | |
| await init_db() | |
| logger.info("database_initialized_successfully") | |
| print("[OK] Database initialized successfully!") | |
| except Exception as e: | |
| logger.error("database_initialization_failed", exc_info=e) | |
| print(f"[ERROR] Database initialization failed: {e}") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |