3.1 KiB
3.1 KiB
Database Migration Summary
Problem
Your production application is throwing SQL errors because:
- The
votingdeadlinecolumn is missing from theadmin_settingstable - 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 queriesreadSettings.py- Added camelCase to snake_case conversion
What You Need to Do
Run the Migration on Production
Option 1: Use the automated script (Easiest)
cd /home/jonny/Projects/gcp-hockey-results/motm_app
./run_production_migration.sh motm-app
Option 2: Manual steps
# 1. Find your pod
kubectl get pods -n motm-app -l app.kubernetes.io/name=motm-app
# 2. Run the migration
kubectl exec -it <POD_NAME> -n motm-app -- python add_voting_deadline.py
# 3. Verify it worked
kubectl exec -it <POD_NAME> -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
votingdeadlinecolumn will be added toadmin_settingstable - ✅ 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:
- Visit https://motm.ervine.cloud/admin/motm
- Page should load without errors
- You should see the "Voting Deadline" field
- Set a deadline and activate voting
- 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:
# 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:
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 guideVOTING_DEADLINE_FEATURE.md- Feature documentationVOTING_DEADLINE_IMPLEMENTATION.md- Implementation details
Support
If you encounter issues:
- Check pod logs for detailed error messages
- Verify database connectivity
- Ensure database user has ALTER TABLE permissions
- Review the production migration guide