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
10 lines
360 B
Python
10 lines
360 B
Python
"""Database integration tests for Mantimon TCG.
|
|
|
|
This package contains tests for SQLAlchemy models, relationships,
|
|
and database operations using real PostgreSQL via testcontainers.
|
|
|
|
Test isolation is achieved through transaction rollback - each test
|
|
runs in a transaction that is rolled back after completion, ensuring
|
|
no test data persists between tests.
|
|
"""
|