Spaces:
Running
Running
Download backend/apply_notification_migration.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/apply_notification_migration.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/apply_notification_migration.py
-
curl -L -o apply_notification_migration.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/apply_notification_migration.py
1.34 kB
| import asyncio | |
| import os | |
| from sqlalchemy import text | |
| from app.core.config import settings | |
| from app.core.database import async_session_maker | |
| async def apply_migration(): | |
| """Add notification_settings to tenants table.""" | |
| print("🚀 Starting migration: Add notification_settings to tenants...") | |
| async with async_session_maker() as session: | |
| try: | |
| # Check if column exists | |
| print("Checking if column exists...") | |
| result = await session.execute(text( | |
| "SELECT column_name FROM information_schema.columns WHERE table_name='tenants' AND column_name='notification_settings'" | |
| )) | |
| if result.scalar(): | |
| print("⚠️ Column 'notification_settings' already exists. Skipping.") | |
| return | |
| print("Adding 'notification_settings' column...") | |
| # Add column | |
| await session.execute(text( | |
| "ALTER TABLE tenants ADD COLUMN notification_settings JSON" | |
| )) | |
| await session.commit() | |
| print("✅ Migration applied successfully: Column 'notification_settings' added.") | |
| except Exception as e: | |
| print(f"❌ Migration failed: {e}") | |
| await session.rollback() | |
| if __name__ == "__main__": | |
| asyncio.run(apply_migration()) | |