69 lines
2.4 KiB
Python
69 lines
2.4 KiB
Python
|
|
"""
|
||
|
|
Card model for trading card data
|
||
|
|
"""
|
||
|
|
|
||
|
|
from sqlalchemy import Column, Integer, String, Text, Float, DateTime, Boolean, JSON
|
||
|
|
from sqlalchemy.orm import relationship
|
||
|
|
from sqlalchemy.sql import func
|
||
|
|
from app.database import Base
|
||
|
|
|
||
|
|
|
||
|
|
class Card(Base):
|
||
|
|
__tablename__ = "cards"
|
||
|
|
|
||
|
|
id = Column(Integer, primary_key=True, index=True)
|
||
|
|
|
||
|
|
# Basic card identification
|
||
|
|
name = Column(String, nullable=False, index=True)
|
||
|
|
set_name = Column(String, index=True)
|
||
|
|
set_code = Column(String, index=True)
|
||
|
|
card_number = Column(String)
|
||
|
|
rarity = Column(String)
|
||
|
|
|
||
|
|
# Game-specific data
|
||
|
|
game = Column(String, nullable=False, index=True) # MTG, Pokemon, YuGiOh, etc.
|
||
|
|
mana_cost = Column(String) # For MTG
|
||
|
|
cmc = Column(Integer) # Converted mana cost
|
||
|
|
card_type = Column(String) # Creature, Instant, Spell, etc.
|
||
|
|
colors = Column(JSON) # Array of colors
|
||
|
|
|
||
|
|
# Card text and rules
|
||
|
|
oracle_text = Column(Text)
|
||
|
|
flavor_text = Column(Text)
|
||
|
|
power = Column(String) # Can be * or numbers
|
||
|
|
toughness = Column(String)
|
||
|
|
loyalty = Column(Integer) # For planeswalkers
|
||
|
|
|
||
|
|
# Visual and identification
|
||
|
|
artist = Column(String)
|
||
|
|
stock_image_url = Column(String) # Official card image
|
||
|
|
artwork_crop_coords = Column(JSON) # Coordinates for artwork cropping {x, y, width, height}
|
||
|
|
scryfall_id = Column(String, unique=True, index=True) # For MTG
|
||
|
|
tcg_player_id = Column(String, index=True)
|
||
|
|
|
||
|
|
# Legacy field for backward compatibility
|
||
|
|
image_url = Column(String)
|
||
|
|
|
||
|
|
# Pricing data
|
||
|
|
current_price = Column(Float)
|
||
|
|
market_price = Column(Float)
|
||
|
|
low_price = Column(Float)
|
||
|
|
high_price = Column(Float)
|
||
|
|
price_last_updated = Column(DateTime)
|
||
|
|
|
||
|
|
# OCR and processing metadata
|
||
|
|
ocr_confidence = Column(Float) # Confidence score from OCR
|
||
|
|
ocr_raw_text = Column(Text) # Raw text extracted by OCR
|
||
|
|
image_path = Column(String) # Path to stored image
|
||
|
|
verified = Column(Boolean, default=False) # Human verified the OCR data
|
||
|
|
|
||
|
|
# Metadata
|
||
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||
|
|
|
||
|
|
# Relationships
|
||
|
|
collection_cards = relationship("CollectionCard", back_populates="card")
|
||
|
|
deck_cards = relationship("DeckCard", back_populates="card")
|
||
|
|
|
||
|
|
def __repr__(self):
|
||
|
|
return f"<Card(id={self.id}, name='{self.name}', set='{self.set_name}')>"
|