Spaces:
Running
Running
Download backend/apply_message_status_migration.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/apply_message_status_migration.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/apply_message_status_migration.py
-
curl -L -o apply_message_status_migration.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/apply_message_status_migration.py
1.36 kB
| import asyncio | |
| import sys | |
| import os | |
| from sqlalchemy import text | |
| # Add backend to path | |
| sys.path.append(os.path.dirname(os.path.abspath(__file__))) | |
| # Fix for Windows | |
| if sys.platform == 'win32': | |
| asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) | |
| from app.core.database import async_session_factory | |
| async def apply_migration(): | |
| print("🔧 Applying 'status' column migration to 'messages' table...") | |
| try: | |
| async with async_session_factory() as session: | |
| # Check if column exists | |
| check_sql = text(""" | |
| SELECT column_name | |
| FROM information_schema.columns | |
| WHERE table_name = 'messages' | |
| AND column_name = 'status' | |
| """) | |
| result = await session.execute(check_sql) | |
| if result.scalar(): | |
| print("⚠️ Column 'status' already exists.") | |
| else: | |
| # Add column | |
| print("➕ Adding 'status' column...") | |
| await session.execute(text("ALTER TABLE messages ADD COLUMN status VARCHAR(20) DEFAULT 'sent'")) | |
| await session.commit() | |
| print("✅ Migration applied successfully!") | |
| except Exception as e: | |
| print(f"❌ Error: {e}") | |
| if __name__ == "__main__": | |
| asyncio.run(apply_migration()) | |