From 13f484e726e29e54a9f77d1a2649567b5c059705 Mon Sep 17 00:00:00 2001 From: Oronemu Date: Fri, 19 Dec 2025 02:28:02 +0700 Subject: [PATCH] Fix migrations 2 --- .../alembic/versions/008_rename_rematch_to_game_choice.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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' """)