pratikbackend / fix_enum_values.py
Antaram's picture
Upload 96 files
7647b38 verified
Raw
History Blame Contribute Delete
880 Bytes
import asyncio
from sqlalchemy import text
from app.core.database import engine
async def fix_enum():
async with engine.begin() as conn:
# Drop and recreate enum with correct lowercase values
# First, alter the column to use text temporarily
await conn.execute(text("ALTER TABLE parties ALTER COLUMN party_type TYPE TEXT"))
# Drop the old enum
await conn.execute(text("DROP TYPE IF EXISTS partytype CASCADE"))
# Create new enum with lowercase values
await conn.execute(text("CREATE TYPE partytype AS ENUM ('awaak', 'jawaak', 'patti_awaak', 'both')"))
# Alter column back to enum
await conn.execute(text("ALTER TABLE parties ALTER COLUMN party_type TYPE partytype USING party_type::partytype"))
print('Fixed enum values to lowercase')
asyncio.run(fix_enum())