Spaces:
Running
Running
Download backend/apply_linkedin_migration.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 2.43 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/apply_linkedin_migration.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/apply_linkedin_migration.py
-
curl -L -o apply_linkedin_migration.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/apply_linkedin_migration.py
2.43 kB
| """ | |
| Apply LinkedIn migration to replace instagram_config with linkedin_config | |
| """ | |
| import asyncio | |
| import sys | |
| from sqlalchemy import text | |
| try: | |
| from app.core.database import engine | |
| except ImportError: | |
| print("❌ Error importing database engine") | |
| print("Make sure to run from backend/ directory") | |
| sys.exit(1) | |
| async def apply_migration(): | |
| """Apply migration to add linkedin_config column""" | |
| try: | |
| async with engine.begin() as conn: | |
| print("🔄 Checking if instagram_config exists...") | |
| # Check if instagram_config exists | |
| result = await conn.execute(text(""" | |
| SELECT column_name | |
| FROM information_schema.columns | |
| WHERE table_name = 'tenants' | |
| AND column_name = 'instagram_config' | |
| """)) | |
| has_instagram = result.fetchone() is not None | |
| if has_instagram: | |
| print("📦 Dropping instagram_config column...") | |
| await conn.execute(text(""" | |
| ALTER TABLE tenants | |
| DROP COLUMN instagram_config | |
| """)) | |
| print("✅ instagram_config dropped") | |
| else: | |
| print("ℹ️ instagram_config doesn't exist (already removed)") | |
| # Check if linkedin_config exists | |
| result = await conn.execute(text(""" | |
| SELECT column_name | |
| FROM information_schema.columns | |
| WHERE table_name = 'tenants' | |
| AND column_name = 'linkedin_config' | |
| """)) | |
| has_linkedin = result.fetchone() is not None | |
| if not has_linkedin: | |
| print("📦 Adding linkedin_config column...") | |
| await conn.execute(text(""" | |
| ALTER TABLE tenants | |
| ADD COLUMN linkedin_config JSON | |
| """)) | |
| print("✅ linkedin_config added") | |
| else: | |
| print("ℹ️ linkedin_config already exists") | |
| print("✅ Migration completed successfully!") | |
| return True | |
| except Exception as e: | |
| print(f"❌ Migration failed: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| return False | |
| if __name__ == "__main__": | |
| asyncio.run(apply_migration()) | |