Spaces:
Running

microfunnel-api / backend /apply_notification_migration.py
axeronis
feat: Implement Order Agent and Admin Notifications
c56f47b
Raw History Blame Contribute Delete
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())