Fix migrations 2
This commit is contained in:
@@ -17,15 +17,17 @@ depends_on = None
|
|||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
# Update event type from 'rematch' to 'game_choice' in events table
|
# Update event type from 'rematch' to 'game_choice' in events table
|
||||||
|
# These UPDATE statements are idempotent - safe to run multiple times
|
||||||
op.execute("UPDATE events SET type = 'game_choice' WHERE type = 'rematch'")
|
op.execute("UPDATE events SET type = 'game_choice' WHERE type = 'rematch'")
|
||||||
|
|
||||||
# Update event_type in assignments table
|
# Update event_type in assignments table
|
||||||
op.execute("UPDATE assignments SET event_type = 'game_choice' WHERE event_type = 'rematch'")
|
op.execute("UPDATE assignments SET event_type = 'game_choice' WHERE event_type = 'rematch'")
|
||||||
|
|
||||||
# Update activity data that references rematch event
|
# Update activity data that references rematch event
|
||||||
|
# Cast JSON to JSONB, apply jsonb_set, then cast back to JSON
|
||||||
op.execute("""
|
op.execute("""
|
||||||
UPDATE activities
|
UPDATE activities
|
||||||
SET data = jsonb_set(data, '{event_type}', '"game_choice"')
|
SET data = jsonb_set(data::jsonb, '{event_type}', '"game_choice"')::json
|
||||||
WHERE data->>'event_type' = 'rematch'
|
WHERE data->>'event_type' = 'rematch'
|
||||||
""")
|
""")
|
||||||
|
|
||||||
@@ -36,6 +38,6 @@ def downgrade() -> None:
|
|||||||
op.execute("UPDATE assignments SET event_type = 'rematch' WHERE event_type = 'game_choice'")
|
op.execute("UPDATE assignments SET event_type = 'rematch' WHERE event_type = 'game_choice'")
|
||||||
op.execute("""
|
op.execute("""
|
||||||
UPDATE activities
|
UPDATE activities
|
||||||
SET data = jsonb_set(data, '{event_type}', '"rematch"')
|
SET data = jsonb_set(data::jsonb, '{event_type}', '"rematch"')::json
|
||||||
WHERE data->>'event_type' = 'game_choice'
|
WHERE data->>'event_type' = 'game_choice'
|
||||||
""")
|
""")
|
||||||
|
|||||||
Reference in New Issue
Block a user