Files
mtgonline/backend/alembic/versions/003_mtgonline_cards_table.py
T
akadmin c23f88cd41 feat: complete deckbuilding feature with local card mirror
- Add MtgonlineCard model (local card data mirror in mtgonline DB)
- Create user_deck.py models (UserDeck, UserDeckCard, DeckPrecedent, CardSuggestion)
- Create user_deck_schemas.py with Pydantic schemas
- Update decks.py router to use local MtgonlineCard instead of cross-DB MtgCard
- Add migration 002 (user deck building tables)
- Add migration 003 (mtgonline_cards table)
- All card lookups now use local mirror for fast queries
- No cross-DB joins in deckbuilding endpoints
2026-07-24 04:42:22 +00:00

56 lines
2.4 KiB
Python

"""Add mtgonline_cards table for local card data mirror
Revision ID: 003
Revises: 002
Create Date: 2026-07-23 00:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '003'
down_revision: Union[str, None] = '002'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Create mtgonline_cards table for local card data mirror."""
op.create_table(
'mtgonline_cards',
sa.Column('id', sa.Integer(), primary_key=True, autoincrement=True),
sa.Column('source_id', sa.Integer(), nullable=True, index=True), # References mtg_cards.id in mtgdata
sa.Column('name', sa.String(255), nullable=False, index=True),
sa.Column('mana_cost', sa.String(255), nullable=True),
sa.Column('type_line', sa.String(255), nullable=True),
sa.Column('oracle_text', sa.Text(), nullable=True),
sa.Column('power', sa.String(50), nullable=True),
sa.Column('toughness', sa.String(50), nullable=True),
sa.Column('rarity', sa.String(50), nullable=True),
sa.Column('layout', sa.String(50), nullable=True),
sa.Column('artist', sa.String(255), nullable=True),
sa.Column('flavor_text', sa.Text(), nullable=True),
sa.Column('numbers', sa.String(100), nullable=True),
sa.Column('identifiers', sa.Text(), nullable=True), # JSON string
sa.Column('images', sa.Text(), nullable=True), # JSON string
sa.Column('image', sa.Text(), nullable=True), # Card image URL
sa.Column('set_code', sa.String(10), nullable=True, index=True),
sa.Column('set_name', sa.String(255), nullable=True),
sa.Column('card_parts', sa.Text(), nullable=True), # Comma-separated face names
sa.Column('keywords', sa.Text(), nullable=True), # Comma-separated keywords
sa.Column('legalities', sa.Text(), nullable=True), # JSON of format legality
sa.Column('synced_at', sa.DateTime(), server_default=sa.func.now(), onupdate=sa.func.now()),
sa.Column('created_at', sa.DateTime(), server_default=sa.func.now()),
)
op.create_index('idx_mtgonline_cards_name', 'mtgonline_cards', ['name'])
op.create_index('idx_mtgonline_cards_set', 'mtgonline_cards', ['set_code'])
def downgrade() -> None:
"""Drop mtgonline_cards table."""
op.drop_table('mtgonline_cards')