Spaces:
Paused
Paused
File size: 1,308 Bytes
b7980f7 | 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 | import asyncio
import sys
import os
# Fix PYTHONPATH: Add project root to sys.path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from sqlalchemy import text
from core.database import async_session_factory
async def fix_escalation_rules():
"""
Sanitize escalation_rules data to match the new EscalationAction enum.
Legacy values like 'string' will be converted to 'NOTIFY_LEAD'.
"""
async with async_session_factory() as db:
print("--- DB SANITIZATION: START ---")
# 1. Update invalid actions to 'NOTIFY_LEAD'
# We use a raw SQL execution to bypass the Enum validation that is breaking the ORM
stmt = text("""
UPDATE escalation_rules
SET action = 'NOTIFY_LEAD'
WHERE action NOT IN ('NOTIFY_LEAD', 'REASSIGN', 'AUTO_RESOLVE');
""")
try:
result = await db.execute(stmt)
await db.commit()
print(f"SUCCESS: Updated {result.rowcount} records to 'NOTIFY_LEAD'.")
except Exception as e:
await db.rollback()
print(f"FAILURE: Could not sanitize DB: {str(e)}")
print("--- DB SANITIZATION: COMPLETE ---")
if __name__ == "__main__":
asyncio.run(fix_escalation_rules())
|