Spaces:
Running
Running
Download backend/create_tables.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/create_tables.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/create_tables.py
-
curl -L -o create_tables.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/create_tables.py
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()) | |