Phase 3: Schema Layer - Pydantic v2 migration, deduplication, and missing schemas
- Migrated all schemas to Pydantic v2 syntax (model_config, ConfigDict) - Fixed mutable default in ProtoMessageBase using Field(default_factory=datetime.now) - Consolidated CardCollection and Wishlist schemas in user_card_collection.py - Created game_schemas.py with GameCreate, GameResponse, GameJoinRequest, etc. - Created mtg_card_schemas.py with MtgCardResponse, MtgCardSearchRequest, etc. - Added CardImportBatchCreate, CardImportBatchResponse, UserCardImportCreate/Response schemas - Fixed duplicate UserCardImportRecord class between card_import_batch.py and user_card_import_record.py - Updated __init__.py with comprehensive schema exports - Created verify_schemas.py for schema-model matching verification
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
"""
|
||||
SQLAlchemy ORM model for user card imports.
|
||||
|
||||
Stores a user's imported card collection as a JSON string containing
|
||||
a list of card names. This is the source data for building decks
|
||||
from the user's actual card collection.
|
||||
This model corresponds to the user_card_imports table created in migration 004.
|
||||
It stores a user's imported card collection as a JSON array of card names.
|
||||
"""
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Text, UniqueConstraint
|
||||
from sqlalchemy import (
|
||||
Column, Integer, String, BigInteger, DateTime, Text,
|
||||
ForeignKey, UniqueConstraint
|
||||
)
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from app.core.database import Base
|
||||
@@ -13,21 +15,26 @@ from app.core.database import Base
|
||||
|
||||
class UserCardImport(Base):
|
||||
"""
|
||||
User's imported card collection.
|
||||
User card import record.
|
||||
|
||||
Stores a JSON string of card names that the user owns.
|
||||
Used as the source for building decks from user's actual cards.
|
||||
Stores a user's imported card collection as a JSON array of card names.
|
||||
This table was created in migration 004 and may be superseded by
|
||||
CardImportBatch and UserCardImportRecord in migration 005.
|
||||
"""
|
||||
__tablename__ = "user_card_imports"
|
||||
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id = Column(Integer, ForeignKey("mtgonline_users.id", ondelete="CASCADE"), nullable=False, unique=True, index=True)
|
||||
user_id = Column(Integer, ForeignKey("mtgonline_users.id", ondelete="CASCADE"), nullable=False)
|
||||
card_names_json = Column(Text, nullable=False) # JSON array of card names
|
||||
created_at = Column(DateTime, server_default=func.now())
|
||||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
||||
|
||||
|
||||
# Relationships
|
||||
user = relationship("User", backref="card_imports")
|
||||
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint('user_id', name='uq_user_card_imports_user_id'),
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<UserCardImport user={self.user_id}>"
|
||||
|
||||
Reference in New Issue
Block a user