Spaces:
Running
Running
File size: 1,190 Bytes
cd61bf7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | """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())
|