From bac02fecf5846934775cee57a69e821ba5b98111 Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Fri, 3 Apr 2026 10:33:24 -0400 Subject: [PATCH] Fix SQLite circular dependency in batch migrations Split batch_alter_table operations to avoid circular dependency errors caused by the current_turn_team_id foreign key during SQLite table recreation. Co-Authored-By: Claude Opus 4.6 --- .../2937635f309a_add_turn_tracking_fields_to_game_model.py | 3 +++ .../9a119272b516_add_question_ownership_and_sharing.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/migrations/versions/2937635f309a_add_turn_tracking_fields_to_game_model.py b/migrations/versions/2937635f309a_add_turn_tracking_fields_to_game_model.py index 064d5d5..d54e837 100644 --- a/migrations/versions/2937635f309a_add_turn_tracking_fields_to_game_model.py +++ b/migrations/versions/2937635f309a_add_turn_tracking_fields_to_game_model.py @@ -18,10 +18,13 @@ depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### + # Split into two batch operations to avoid SQLite circular dependency error with op.batch_alter_table('games', schema=None) as batch_op: batch_op.add_column(sa.Column('current_turn_team_id', sa.Integer(), nullable=True)) batch_op.add_column(sa.Column('turn_order', sa.JSON(), nullable=True)) batch_op.add_column(sa.Column('is_steal_mode', sa.Boolean(), nullable=True)) + + with op.batch_alter_table('games', schema=None) as batch_op: batch_op.create_foreign_key('fk_games_current_turn_team', 'teams', ['current_turn_team_id'], ['id']) # ### end Alembic commands ### diff --git a/migrations/versions/9a119272b516_add_question_ownership_and_sharing.py b/migrations/versions/9a119272b516_add_question_ownership_and_sharing.py index bfe3f99..c066b54 100644 --- a/migrations/versions/9a119272b516_add_question_ownership_and_sharing.py +++ b/migrations/versions/9a119272b516_add_question_ownership_and_sharing.py @@ -30,9 +30,13 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('question_id', 'shared_with_user_id', name='unique_question_share') ) + # Split into separate batch operations to avoid SQLite circular dependency + # with the existing current_turn_team_id foreign key with op.batch_alter_table('games', schema=None) as batch_op: batch_op.add_column(sa.Column('completed_at', sa.DateTime(), nullable=True)) batch_op.add_column(sa.Column('winners', sa.JSON(), nullable=True)) + + with op.batch_alter_table('games', schema=None) as batch_op: batch_op.drop_column('turn_order') batch_op.drop_column('is_steal_mode')