Phase 1 Database Implementation (DB-001 through DB-012): Models: - User: OAuth support (Google/Discord), premium subscriptions - Collection: Card ownership with CardSource enum - Deck: JSONB cards/energy_cards, validation state - CampaignProgress: One-to-one with User, medals/NPCs as JSONB - ActiveGame: In-progress games with GameType enum - GameHistory: Completed games with EndReason enum, replay data Infrastructure: - Alembic migrations with sync psycopg2 (avoids async issues) - Docker Compose for Postgres (5433) and Redis (6380) - App config with Pydantic settings - Redis client helper Test Infrastructure: - 68 database tests (47 model + 21 relationship) - Async factory pattern for test data creation - Sync TRUNCATE cleanup (solves pytest-asyncio event loop mismatch) - Uses dev containers instead of testcontainers for reliability Key technical decisions: - passive_deletes=True for ON DELETE SET NULL relationships - NullPool for test sessions (no connection reuse) - expire_on_commit=False with manual expire() for relationship tests
46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
"""Database models for Mantimon TCG.
|
|
|
|
This module exports all SQLAlchemy models for the application.
|
|
|
|
Models:
|
|
- User: User accounts with OAuth support
|
|
- Collection: Player card collections
|
|
- Deck: Player deck configurations
|
|
- CampaignProgress: Single-player campaign state
|
|
- ActiveGame: In-progress game state
|
|
- GameHistory: Completed game records
|
|
|
|
Usage:
|
|
from app.db.models import User, Deck, Collection
|
|
|
|
user = User(
|
|
email="player@example.com",
|
|
display_name="Player1",
|
|
oauth_provider="google",
|
|
oauth_id="123456789"
|
|
)
|
|
"""
|
|
|
|
from app.db.models.campaign import CampaignProgress
|
|
from app.db.models.collection import CardSource, Collection
|
|
from app.db.models.deck import Deck
|
|
from app.db.models.game import ActiveGame, EndReason, GameHistory, GameType
|
|
from app.db.models.user import User
|
|
|
|
__all__ = [
|
|
# User
|
|
"User",
|
|
# Collection
|
|
"Collection",
|
|
"CardSource",
|
|
# Deck
|
|
"Deck",
|
|
# Campaign
|
|
"CampaignProgress",
|
|
# Game
|
|
"ActiveGame",
|
|
"GameHistory",
|
|
"GameType",
|
|
"EndReason",
|
|
]
|