Spaces:
Running
Running
File size: 1,341 Bytes
727ec8d c56f47b 727ec8d c56f47b 727ec8d c56f47b 727ec8d c56f47b | 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 | 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())
|