Spaces:
Paused
Paused
Download scripts/migrate_escalation_enum.py from 3SCError404/miracle: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/spaces/3SCError404/miracle/resolve/main/scripts/migrate_escalation_enum.py
- Command line
-
hf download hf://spaces/3SCError404/miracle/scripts/migrate_escalation_enum.py
-
curl -L -o migrate_escalation_enum.py https://huggingface.co/spaces/3SCError404/miracle/resolve/main/scripts/migrate_escalation_enum.py
1.57 kB
| 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 migrate_enum_type(): | |
| """ | |
| Create the native PG enum type for EscalationAction and migrate the column. | |
| This resolves the 'type "escalationaction" does not exist' error. | |
| """ | |
| async with async_session_factory() as db: | |
| print("--- DB MIGRATION: ENUM TYPE ---") | |
| # 1. Create Type (if not exists) | |
| # 2. Alter column to use the new type | |
| # Note: We use raw SQL because Alembic isn't being run manually here. | |
| commands = [ | |
| # Check if type exists first or just try-catch | |
| "DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'escalationaction') THEN CREATE TYPE escalationaction AS ENUM ('NOTIFY_LEAD', 'REASSIGN', 'AUTO_RESOLVE'); END IF; END $$;", | |
| "ALTER TABLE escalation_rules ALTER COLUMN action TYPE escalationaction USING action::escalationaction;" | |
| ] | |
| for cmd in commands: | |
| try: | |
| print(f"Executing: {cmd}") | |
| await db.execute(text(cmd)) | |
| await db.commit() | |
| print("SUCCESS.") | |
| except Exception as e: | |
| await db.rollback() | |
| print(f"SKIPPED/FAILED: {str(e)}") | |
| print("--- DB MIGRATION: COMPLETE ---") | |
| if __name__ == "__main__": | |
| asyncio.run(migrate_enum_type()) | |