Spaces:
Running
Running
File size: 1,360 Bytes
2fd367f | 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 | 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())
|