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())