"""Script to create all database tables.""" import asyncio from sqlalchemy import text from app.core.database import async_engine from sqlmodel import SQLModel # Import all models to ensure they're registered from app.models import Tenant, Partner, Lead, KnowledgeBase, User async def create_tables(): """Create all tables in the database.""" async with async_engine.begin() as conn: # Drop all tables first (optional - comment out if you want to keep existing data) # await conn.run_sync(SQLModel.metadata.drop_all) # print("āœ… Dropped all tables") # Create all tables await conn.run_sync(SQLModel.metadata.create_all) print("āœ… Created all tables") # List all tables result = await conn.execute(text(""" SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name; """)) tables = result.fetchall() print(f"\nšŸ“‹ Tables in database ({len(tables)}):") for table in tables: print(f" - {table[0]}") if __name__ == "__main__": asyncio.run(create_tables())