- Add Alembic migration setup with async configuration - Create 16 user data models (users, decks, cards, replays, etc.) - Implement comprehensive API endpoints with JWT auth - Add replay, card collection, group, network, preferences, and activity log routers - Include API documentation and migration test plan - Update Dockerfile to run migrations on startup
4.4 KiB
4.4 KiB
Alembic Migration Test Plan
Overview
Test the Alembic migration setup to verify all user data tables are created correctly in PostgreSQL.
Test Steps
1. Verify File Structure
- Create
alembic.iniwith database URL configuration - Create
alembic/env.pywith async Alembic environment - Create
alembic/versions/001_initial_user_schema.pywith migration script - Create
alembic/versions/__init__.py - Create
app/models/user_data.pywith all new models - Update
app/models/__init__.pyto import new models - Update
Dockerfileto run migrations on container startup - Create
scripts/run_migrations.shfor migration execution
2. Test Migration Execution
- Verify Alembic configuration is correct
- Test migration in offline mode
- Test migration in online mode (if database is available)
- Verify all tables are created with correct schema
3. Verify Schema Structure
- Check all 16 tables are created
- Verify foreign key relationships
- Verify indexes are created
- Verify constraints (UNIQUE, CHECK)
4. Test Data Operations
- Insert test data into each table
- Verify CASCADE deletes work correctly
- Verify UNIQUE constraints prevent duplicates
- Verify JSONB columns store data correctly
5. Test Rollback
- Execute downgrade migration
- Verify all tables are dropped
- Verify columns are removed from existing tables
Files Created
Core Alembic Files
- alembic.ini - Alembic configuration with database URL
- alembic/env.py - Async Alembic environment for PostgreSQL
- alembic/versions/001_initial_user_schema.py - Initial migration script
New Models
- app/models/user_data.py - All user data models (16 models)
- UserSession, DeckVersion, GameReplay, ReplayPlayer
- GameOutcome, UserStatistics, UserCardCollection, CardWishlist
- UserGroup, GroupMember, GroupChatMessage
- UserNetwork, NetworkMember, UserPreference, UserActivityLog
Updated Files
- app/models/__init__.py - Added imports for new models
- Dockerfile - Added migration step to container startup
- scripts/run_migrations.sh - Migration execution script
Expected Tables
User Authentication
user_sessions- Session management with token hashing
Deck Management
mtgonline_decklist_files- Enhanced with description, format, etc.deck_versions- Deck version history
Game Tracking
game_replays- Game replay recordingsreplay_players- Players in game replaysgame_outcomes- Game win/loss recordsuser_statistics- User game statistics summary
Card Collection
user_card_collection- User-owned cardscard_wishlist- Cards users want
Social Features
user_groups- User groupsgroup_members- Group membershipgroup_chat_messages- Group chatuser_networks- Extended social connectionsnetwork_members- Network membership
User Settings
user_preferences- User preferences and settingsuser_activity_log- User activity tracking
Migration Commands
Run Migrations
# Online mode (requires database connection)
alembic upgrade head
# Offline mode (for testing schema generation)
alembic upgrade head --sql
# Check migration status
alembic current
alembic history
# Generate new migration (after model changes)
alembic revision --autogenerate -m "Description"
Test Commands
# Test alembic configuration
alembic --config alembic.ini current
# Test migration generation
alembic --config alembic.ini upgrade head --sql
# Run migration
alembic --config alembic.ini upgrade head
Success Criteria
- All 16 tables created successfully
- All foreign keys established correctly
- All indexes created for performance
- All constraints enforced properly
- Migration can be rolled back successfully
- Container starts with migrations applied
Potential Issues
- Database connection - Ensure PostgreSQL is accessible at
postgres:5432 - Model imports - Verify all models are imported in env.py
- Column conflicts - Check for existing columns in mtgonline_decklist_files
- Index naming - Ensure index names don't conflict with existing indexes
Next Steps
- Run the container and verify migrations execute
- Test data insertion and retrieval
- Verify CASCADE deletes work correctly
- Test downgrade migration
- Create API endpoints for new features