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:
@@ -138,8 +138,7 @@ def upgrade() -> None:
|
||||
sa.Column('created_at', sa.DateTime(), server_default=sa.func.now()),
|
||||
sa.Column('updated_at', sa.DateTime(), server_default=sa.func.now(), onupdate=sa.func.now()),
|
||||
)
|
||||
op.create_index('idx_collection_user', 'user_card_collection', ['user_id'])
|
||||
op.create_index('idx_collection_card', 'user_card_collection', ['card_id'])
|
||||
op.create_index('idx_collection_user_card', 'user_card_collection', ['user_id', 'card_id'])
|
||||
op.create_unique_constraint('uq_collection_unique', 'user_card_collection', ['user_id', 'card_id', 'is_foil', 'is_alt_art'])
|
||||
|
||||
# 9. Card Wishlist Table
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
"""Add mtgonline_cards table for local card data mirror
|
||||
"""Add mtgonline_cards table and deck building junction tables
|
||||
|
||||
Revision ID: 003
|
||||
Revises: 002
|
||||
@@ -4,13 +4,13 @@ Revision ID: 005
|
||||
Revises: 004
|
||||
Create Date: 2026-01-05 00:00:00.000000
|
||||
|
||||
This migration creates the following tables, importing model definitions
|
||||
from their respective source files to ensure column-level accuracy:
|
||||
This migration creates the following tables using raw column definitions
|
||||
to avoid circular import issues with the ORM models.
|
||||
|
||||
- mtg_sets, mtg_cards → app/models/mtg_models.py
|
||||
- mtg_cards_mirror, deck_card_links → app/models/mirror_models.py
|
||||
- card_import_batches → app/models/card_import_batch.py
|
||||
- user_card_imports_confirmed → app/models/user_card_import_record.py
|
||||
- mtg_sets, mtg_cards → raw definitions (mirrors mtg_models.py)
|
||||
- mtg_cards_mirror, deck_card_links → raw definitions (mirrors mirror_models.py)
|
||||
- card_import_batches → raw definitions (mirrors card_import_batch.py)
|
||||
- user_card_imports_confirmed → raw definitions (mirrors user_card_import_record.py)
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
@@ -18,15 +18,6 @@ from typing import Sequence, Union
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Model imports – one import per source file so column definitions stay
|
||||
# synchronised with the ORM classes.
|
||||
# ---------------------------------------------------------------------------
|
||||
from app.models.mtg_models import MtgSet, MtgCard
|
||||
from app.models.mirror_models import MtgCardMirror, DeckCardLink
|
||||
from app.models.card_import_batch import CardImportBatch
|
||||
from app.models.user_card_import_record import UserCardImportRecord
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '005'
|
||||
down_revision: Union[str, None] = '004'
|
||||
@@ -35,14 +26,11 @@ depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Create missing tables for MTG data, card imports, and card mirrors.
|
||||
|
||||
Column definitions are taken directly from the ORM models imported above.
|
||||
"""
|
||||
"""Create missing tables for MTG data, card imports, and card mirrors."""
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 1. MTG Sets Table (mtg_sets)
|
||||
# Source: app/models/mtg_models.py – class MtgSet
|
||||
# Mirrors: app/models/mtg_models.py – class MtgSet
|
||||
# ------------------------------------------------------------------
|
||||
op.create_table(
|
||||
'mtg_sets',
|
||||
@@ -66,7 +54,7 @@ def upgrade() -> None:
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 2. MTG Cards Table (mtg_cards)
|
||||
# Source: app/models/mtg_models.py – class MtgCard
|
||||
# Mirrors: app/models/mtg_models.py – class MtgCard
|
||||
# ------------------------------------------------------------------
|
||||
op.create_table(
|
||||
'mtg_cards',
|
||||
@@ -97,7 +85,7 @@ def upgrade() -> None:
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 3. MTG Cards Mirror Table (mtg_cards_mirror)
|
||||
# Source: app/models/mirror_models.py – class MtgCardMirror
|
||||
# Mirrors: app/models/mirror_models.py – class MtgCardMirror
|
||||
# ------------------------------------------------------------------
|
||||
op.create_table(
|
||||
'mtg_cards_mirror',
|
||||
@@ -129,7 +117,7 @@ def upgrade() -> None:
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 4. Card Import Batches Table (card_import_batches)
|
||||
# Source: app/models/card_import_batch.py – class CardImportBatch
|
||||
# Mirrors: app/models/card_import_batch.py – class CardImportBatch
|
||||
# ------------------------------------------------------------------
|
||||
op.create_table(
|
||||
'card_import_batches',
|
||||
@@ -154,7 +142,7 @@ def upgrade() -> None:
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 5. User Card Imports Confirmed Table (user_card_imports_confirmed)
|
||||
# Source: app/models/user_card_import_record.py –
|
||||
# Mirrors: app/models/user_card_import_record.py –
|
||||
# class UserCardImportRecord
|
||||
# ------------------------------------------------------------------
|
||||
op.create_table(
|
||||
@@ -172,7 +160,7 @@ def upgrade() -> None:
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 6. Deck Card Links Table (deck_card_links)
|
||||
# Source: app/models/mirror_models.py – class DeckCardLink
|
||||
# Mirrors: app/models/mirror_models.py – class DeckCardLink
|
||||
# ------------------------------------------------------------------
|
||||
op.create_table(
|
||||
'deck_card_links',
|
||||
|
||||
Reference in New Issue
Block a user