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 <noreply@anthropic.com>
This commit is contained in:
@@ -18,10 +18,13 @@ depends_on = None
|
|||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### 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:
|
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('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('turn_order', sa.JSON(), nullable=True))
|
||||||
batch_op.add_column(sa.Column('is_steal_mode', sa.Boolean(), 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'])
|
batch_op.create_foreign_key('fk_games_current_turn_team', 'teams', ['current_turn_team_id'], ['id'])
|
||||||
|
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
|
|||||||
@@ -30,9 +30,13 @@ def upgrade():
|
|||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
sa.UniqueConstraint('question_id', 'shared_with_user_id', name='unique_question_share')
|
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:
|
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('completed_at', sa.DateTime(), nullable=True))
|
||||||
batch_op.add_column(sa.Column('winners', sa.JSON(), 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('turn_order')
|
||||||
batch_op.drop_column('is_steal_mode')
|
batch_op.drop_column('is_steal_mode')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user