Spaces:
Running

microfunnel-api / backend /create_tables.py
MicroFunnel
Production-ready: Refactored codebase with Railway + Vercel config
cd61bf7
Raw History Blame Contribute Delete
1.19 kB
"""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())