Spaces:
3SCError404
/
Paused

File size: 1,389 Bytes
5eb4857
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 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())