diff --git a/backend/alembic/versions/008_rename_rematch_to_game_choice.py b/backend/alembic/versions/008_rename_rematch_to_game_choice.py index 5d63495..3b3cf39 100644 --- a/backend/alembic/versions/008_rename_rematch_to_game_choice.py +++ b/backend/alembic/versions/008_rename_rematch_to_game_choice.py @@ -17,15 +17,17 @@ depends_on = None def upgrade() -> None: # 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'") # Update event_type in assignments table op.execute("UPDATE assignments SET event_type = 'game_choice' WHERE event_type = 'rematch'") # Update activity data that references rematch event + # Cast JSON to JSONB, apply jsonb_set, then cast back to JSON op.execute(""" 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' """) @@ -36,6 +38,6 @@ def downgrade() -> None: op.execute("UPDATE assignments SET event_type = 'rematch' WHERE event_type = 'game_choice'") op.execute(""" 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' """)