Spaces:
Running
Running
Download backend/apply_booking_schema.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/apply_booking_schema.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/apply_booking_schema.py
-
curl -L -o apply_booking_schema.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/apply_booking_schema.py
1.38 kB
| from dotenv import load_dotenv | |
| load_dotenv() | |
| import asyncio | |
| import logging | |
| from sqlalchemy.ext.asyncio import create_async_engine | |
| from sqlmodel import SQLModel, text | |
| from app.core.config import settings | |
| from app.models.booking import Service, Availability, Appointment | |
| # Also import other models to ensure relationships resolve if needed, though SQLModel usually handles it via strings | |
| from app.models.tenant import Tenant | |
| from app.models.lead import Lead | |
| # Configure logging | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| async def apply_schema(): | |
| """ | |
| Applies the Booking schema changes to the database. | |
| """ | |
| logger.info("Connecting to database...") | |
| # Ensure async driver | |
| url = settings.DATABASE_URL | |
| if url.startswith("postgresql://"): | |
| url = url.replace("postgresql://", "postgresql+asyncpg://") | |
| engine = create_async_engine(url, echo=True) | |
| async with engine.begin() as conn: | |
| logger.info("Creating Booking tables...") | |
| # Create tables using SQLModel metadata | |
| # checkfirst=True prevents error if table exists, but we want to ensure columns are right | |
| await conn.run_sync(SQLModel.metadata.create_all) | |
| logger.info("✅ Booking tables applied successfully!") | |
| await engine.dispose() | |
| if __name__ == "__main__": | |
| asyncio.run(apply_schema()) | |