Spaces:
Paused
Paused
Download scripts/fix_ticket_schema_final.py from 3SCError404/miracle: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/3SCError404/miracle/resolve/main/scripts/fix_ticket_schema_final.py
- Command line
-
hf download hf://spaces/3SCError404/miracle/scripts/fix_ticket_schema_final.py
-
curl -L -o fix_ticket_schema_final.py https://huggingface.co/spaces/3SCError404/miracle/resolve/main/scripts/fix_ticket_schema_final.py
1.39 kB
| import asyncio | |
| import sys | |
| import os | |
| from sqlalchemy import text | |
| # Add project root to path for imports | |
| sys.path.append(os.getcwd()) | |
| from core.database import async_session_factory | |
| from core.logging import get_logger | |
| logger = get_logger(__name__) | |
| async def fix_ticket_schema(): | |
| """Adds missing columns to the tickets table.""" | |
| async with async_session_factory() as db: | |
| # 1. Add is_escalated column (DateTime) | |
| try: | |
| print("Adding 'is_escalated' column...") | |
| await db.execute(text("ALTER TABLE tickets ADD COLUMN IF NOT EXISTS is_escalated TIMESTAMP WITHOUT TIME ZONE")) | |
| await db.commit() | |
| print("Added 'is_escalated'.") | |
| except Exception as e: | |
| await db.rollback() | |
| print(f"Column 'is_escalated' might already exist: {e}") | |
| # 2. Add duplicate_of_id column (UUID) | |
| try: | |
| print("Adding 'duplicate_of_id' column...") | |
| await db.execute(text("ALTER TABLE tickets ADD COLUMN IF NOT EXISTS duplicate_of_id UUID REFERENCES tickets(id)")) | |
| await db.commit() | |
| print("Added 'duplicate_of_id'.") | |
| except Exception as e: | |
| await db.rollback() | |
| print(f"Column 'duplicate_of_id' might already exist: {e}") | |
| print("\nDatabase schema fix complete.") | |
| if __name__ == "__main__": | |
| asyncio.run(fix_ticket_schema()) | |