# Database Migration Summary ## Problem Your production application is throwing SQL errors because: 1. The `votingdeadline` column is missing from the `admin_settings` table 2. The code was using wrong table/column names (fixed in code) ## What Was Fixed ### Code Changes (Already Applied) ✅ Fixed table name: `motmadminsettings` → `admin_settings` ✅ Fixed column names to use snake_case (e.g., `nextclub` → `next_club`) ✅ Added camelCase to snake_case conversion in `readSettings.py` ✅ Improved error handling for duplicate column creation ### Files Modified - `main.py` - Updated all SQL queries - `readSettings.py` - Added camelCase to snake_case conversion ## What You Need to Do ### Run the Migration on Production **Option 1: Use the automated script (Easiest)** ```bash cd /home/jonny/Projects/gcp-hockey-results/motm_app ./run_production_migration.sh motm-app ``` **Option 2: Manual steps** ```bash # 1. Find your pod kubectl get pods -n motm-app -l app.kubernetes.io/name=motm-app # 2. Run the migration kubectl exec -it -n motm-app -- python add_voting_deadline.py # 3. Verify it worked kubectl exec -it -n motm-app -- python -c " from db_config import db_config from sqlalchemy import text, inspect engine = db_config.engine inspector = inspect(engine) columns = inspector.get_columns('admin_settings') print('✓ votingdeadline exists' if any(c['name'] == 'votingdeadline' for c in columns) else '✗ missing') " # 4. Restart the pod kubectl rollout restart deployment/motm-app -n motm-app ``` ## Expected Results After running the migration: - ✅ The `votingdeadline` column will be added to `admin_settings` table - ✅ The MOTM admin page will load without SQL errors - ✅ You'll see the "Voting Deadline" field in the form - ✅ You can set voting deadlines for matches ## Verification Test the application: 1. Visit https://motm.ervine.cloud/admin/motm 2. Page should load without errors 3. You should see the "Voting Deadline" field 4. Set a deadline and activate voting 5. Visit the voting page - you should see a countdown timer ## Troubleshooting ### If the migration script isn't in the pod: You need to rebuild and redeploy the Docker image: ```bash # Build new image with migration script docker build -t your-registry/motm-app:latest . # Push to registry docker push your-registry/motm-app:latest # Deploy to Kubernetes helm upgrade motm-app ./helm-chart/motm-app --namespace motm-app ``` ### If you get "column already exists" error: This is fine! The migration script is idempotent and will skip if the column already exists. ### If you get other errors: Check the logs: ```bash kubectl logs -n motm-app -l app.kubernetes.io/name=motm-app --tail=100 ``` ## Documentation For detailed instructions, see: - `PRODUCTION_MIGRATION_GUIDE.md` - Comprehensive migration guide - `VOTING_DEADLINE_FEATURE.md` - Feature documentation - `VOTING_DEADLINE_IMPLEMENTATION.md` - Implementation details ## Support If you encounter issues: 1. Check pod logs for detailed error messages 2. Verify database connectivity 3. Ensure database user has ALTER TABLE permissions 4. Review the production migration guide