Files
wiki-tcg/backend/alembic/versions/f4e8a1b2c3d9_add_fk_indices.py
2026-04-01 18:31:33 +02:00

41 lines
1.7 KiB
Python

"""add fk indices
Revision ID: f4e8a1b2c3d9
Revises: 29da7c818b01
Create Date: 2026-03-29 00:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
# revision identifiers, used by Alembic.
revision: str = 'f4e8a1b2c3d9'
down_revision: Union[str, None] = '29da7c818b01'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Add indices on FK columns that are missing them."""
op.create_index('ix_cards_user_id', 'cards', ['user_id'])
op.create_index('ix_decks_user_id', 'decks', ['user_id'])
op.create_index('ix_notifications_user_id', 'notifications', ['user_id'])
op.create_index('ix_friendships_requester_id', 'friendships', ['requester_id'])
op.create_index('ix_friendships_addressee_id', 'friendships', ['addressee_id'])
# Composite indices mirror the trade_proposals pattern: filter by owner + status together
op.create_index('ix_game_challenges_challenger_status', 'game_challenges', ['challenger_id', 'status'])
op.create_index('ix_game_challenges_challenged_status', 'game_challenges', ['challenged_id', 'status'])
def downgrade() -> None:
"""Drop FK indices."""
op.drop_index('ix_game_challenges_challenged_status', table_name='game_challenges')
op.drop_index('ix_game_challenges_challenger_status', table_name='game_challenges')
op.drop_index('ix_friendships_addressee_id', table_name='friendships')
op.drop_index('ix_friendships_requester_id', table_name='friendships')
op.drop_index('ix_notifications_user_id', table_name='notifications')
op.drop_index('ix_decks_user_id', table_name='decks')
op.drop_index('ix_cards_user_id', table_name='cards')