Spaces:
Running

microfunnel-api / backend /apply_message_status_migration.py
axeronis
feat: Implement message delivery status verification (Telegram & WhatsApp)
2fd367f
Raw History Blame Contribute Delete
1.36 kB
import asyncio
import sys
import os
from sqlalchemy import text
# Add backend to path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Fix for Windows
if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
from app.core.database import async_session_factory
async def apply_migration():
print("🔧 Applying 'status' column migration to 'messages' table...")
try:
async with async_session_factory() as session:
# Check if column exists
check_sql = text("""
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'messages'
AND column_name = 'status'
""")
result = await session.execute(check_sql)
if result.scalar():
print("⚠️ Column 'status' already exists.")
else:
# Add column
print("➕ Adding 'status' column...")
await session.execute(text("ALTER TABLE messages ADD COLUMN status VARCHAR(20) DEFAULT 'sent'"))
await session.commit()
print("✅ Migration applied successfully!")
except Exception as e:
print(f"❌ Error: {e}")
if __name__ == "__main__":
asyncio.run(apply_migration())