Spaces:
Running
Running
File size: 2,425 Bytes
f838761 280fa78 f838761 280fa78 f838761 280fa78 f838761 280fa78 f838761 280fa78 f838761 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | """
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())
|