# Quick Start - Database Migration ## Apply the Migration ```bash cd /opt/audiOhm/backend # Option 1: Using the helper script ./run_migration.sh upgrade # Option 2: Using Alembic directly alembic upgrade head ``` ## Verify Migration Success ```bash # Check current version ./run_migration.sh current # Or using Alembic directly alembic current ``` ## What Gets Created Two new tables will be created: 1. **listening_history** - Track listening records for users 2. **liked_tracks** - User's favorite/liked tracks ## Need Help? ```bash # Show all available commands ./run_migration.sh help # Or read the full guide cat ALEMBIC_GUIDE.md ``` ## Revert if Needed ```bash # Revert the migration ./run_migration.sh downgrade-1 # Or using Alembic alembic downgrade -1 ``` ## Check Tables in Database ```bash sudo -u postgres psql spotify_le_2 \dt \q ``` ## Important Notes - Make sure PostgreSQL is running before applying migration - The migration uses CASCADE deletes - deleting a user or track will automatically remove related history/likes - The `liked_tracks` table has a UNIQUE constraint to prevent duplicate likes - Both tables have optimized indexes for common queries ## Status ✅ Migration file created and validated ✅ Ready to apply to database ✅ Full downgrade support included ✅ Documentation complete