|
| 1 | +# Deployment Guide: Removing Speakers App |
| 2 | + |
| 3 | +This guide explains how to safely deploy PR #161 which removes the speakers app from the Python Ireland website. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +PR #161 removes the entire `speakers` Django app and all associated code. A database migration has been created to cleanly drop the speakers tables from production. |
| 8 | + |
| 9 | +## Pre-requisites |
| 10 | + |
| 11 | +✅ All speaker/session records have been deleted from production database |
| 12 | +✅ No Wagtail pages of type SpeakersPage or TalksPage exist in production |
| 13 | +✅ Recent database backup exists |
| 14 | + |
| 15 | +## Deployment Steps |
| 16 | + |
| 17 | +### Step 1: Create a Backup |
| 18 | + |
| 19 | +**CRITICAL**: Always backup before running destructive migrations. |
| 20 | + |
| 21 | +```bash |
| 22 | +# Create a fresh backup |
| 23 | +task heroku:database:run-backup |
| 24 | + |
| 25 | +# Verify the backup was created |
| 26 | +task heroku:database:backups |
| 27 | +``` |
| 28 | + |
| 29 | +### Step 2: Merge the PR |
| 30 | + |
| 31 | +Merge PR #161 into master branch: |
| 32 | + |
| 33 | +```bash |
| 34 | +# Via GitHub CLI |
| 35 | +gh pr merge 161 --squash --delete-branch |
| 36 | + |
| 37 | +# Or via GitHub web interface |
| 38 | +``` |
| 39 | + |
| 40 | +### Step 3: Deploy to Heroku |
| 41 | + |
| 42 | +The deployment will happen automatically if auto-deploy is configured, or manually: |
| 43 | + |
| 44 | +```bash |
| 45 | +# Pull latest master |
| 46 | +git checkout master |
| 47 | +git pull origin master |
| 48 | + |
| 49 | +# Push to Heroku (if manual deployment) |
| 50 | +git push heroku master |
| 51 | +``` |
| 52 | + |
| 53 | +### Step 4: Run the Migration |
| 54 | + |
| 55 | +The migration will run automatically during Heroku release phase. If you need to run it manually: |
| 56 | + |
| 57 | +```bash |
| 58 | +# Run migrations on Heroku |
| 59 | +task heroku:migrate |
| 60 | + |
| 61 | +# Or directly: |
| 62 | +heroku run python pythonie/manage.py migrate --settings=pythonie.settings.production |
| 63 | +``` |
| 64 | + |
| 65 | +The migration `0010_remove_speakers_tables` will: |
| 66 | +- Drop `speakers_session_speakers` (M2M table) |
| 67 | +- Drop `speakers_session` |
| 68 | +- Drop `speakers_speaker` |
| 69 | +- Drop `speakers_room` |
| 70 | +- Drop `speakers_talkspage` |
| 71 | +- Drop `speakers_speakerspage` |
| 72 | + |
| 73 | +### Step 5: Verify Deployment |
| 74 | + |
| 75 | +```bash |
| 76 | +# Check application logs |
| 77 | +task heroku:logs |
| 78 | + |
| 79 | +# Verify app is running |
| 80 | +heroku ps |
| 81 | + |
| 82 | +# Test the website |
| 83 | +curl -I https://python.ie |
| 84 | + |
| 85 | +# Verify migration ran |
| 86 | +heroku run python pythonie/manage.py showmigrations core --settings=pythonie.settings.production |
| 87 | +``` |
| 88 | + |
| 89 | +You should see `[X] 0010_remove_speakers_tables` in the output. |
| 90 | + |
| 91 | +### Step 6: Verify Tables Were Dropped |
| 92 | + |
| 93 | +```bash |
| 94 | +# Connect to production database |
| 95 | +heroku pg:psql |
| 96 | + |
| 97 | +# Check for speakers tables (should return no rows) |
| 98 | +\dt speakers_* |
| 99 | + |
| 100 | +# Exit psql |
| 101 | +\q |
| 102 | +``` |
| 103 | + |
| 104 | +## Rollback Procedure |
| 105 | + |
| 106 | +⚠️ **WARNING**: The migration is IRREVERSIBLE by design. |
| 107 | + |
| 108 | +If you need to rollback: |
| 109 | + |
| 110 | +1. **Restore from backup**: |
| 111 | + ```bash |
| 112 | + # List backups |
| 113 | + heroku pg:backups |
| 114 | + |
| 115 | + # Restore from backup (replace b001 with your backup ID) |
| 116 | + heroku pg:backups:restore b001 DATABASE_URL |
| 117 | + ``` |
| 118 | + |
| 119 | +2. **Revert the code**: |
| 120 | + ```bash |
| 121 | + # Rollback Heroku release |
| 122 | + task heroku:rollback |
| 123 | + |
| 124 | + # Or force push previous commit |
| 125 | + git checkout <previous-commit-sha> |
| 126 | + git push heroku HEAD:master --force |
| 127 | + ``` |
| 128 | + |
| 129 | +## Troubleshooting |
| 130 | + |
| 131 | +### Migration fails with "table does not exist" |
| 132 | + |
| 133 | +This is OK if the tables were already manually dropped. The migration uses `DROP TABLE IF EXISTS` so it won't error. |
| 134 | + |
| 135 | +### Application won't start after deployment |
| 136 | + |
| 137 | +Check logs for the specific error: |
| 138 | +```bash |
| 139 | +task heroku:logs |
| 140 | +``` |
| 141 | + |
| 142 | +Common issues: |
| 143 | +- Missing environment variable |
| 144 | +- Database connection issue |
| 145 | +- Code import error |
| 146 | + |
| 147 | +### Need to verify migration status |
| 148 | + |
| 149 | +```bash |
| 150 | +# Show all migrations and their status |
| 151 | +heroku run python pythonie/manage.py showmigrations --settings=pythonie.settings.production |
| 152 | +``` |
| 153 | + |
| 154 | +## Post-Deployment Cleanup |
| 155 | + |
| 156 | +After successful deployment, clean up your local environment: |
| 157 | + |
| 158 | +```bash |
| 159 | +# Remove the worktree |
| 160 | +cd /Users/stephane/src/PythonIreland/website |
| 161 | +git worktree remove /Users/stephane/src/PythonIreland/pythonie-remove-speakers |
| 162 | + |
| 163 | +# Delete local branch |
| 164 | +git branch -d remove-speakers |
| 165 | + |
| 166 | +# Verify worktrees |
| 167 | +git worktree list |
| 168 | +``` |
| 169 | + |
| 170 | +## Migration Details |
| 171 | + |
| 172 | +**File**: `pythonie/core/migrations/0010_remove_speakers_tables.py` |
| 173 | + |
| 174 | +**What it does**: |
| 175 | +- Uses raw SQL to drop speakers tables |
| 176 | +- Handles CASCADE for foreign key constraints |
| 177 | +- Drops tables in correct dependency order |
| 178 | +- Is irreversible (raises RuntimeError on reverse) |
| 179 | + |
| 180 | +**Why in core app**: |
| 181 | +The speakers app has been completely removed from the codebase, so the migration must live in another app (core was chosen as it's the base app). |
| 182 | + |
| 183 | +## Notes |
| 184 | + |
| 185 | +- This migration does NOT delete data - data should be deleted before running the migration |
| 186 | +- The migration is idempotent - safe to run multiple times |
| 187 | +- All table drops use CASCADE to handle foreign keys |
| 188 | +- The migration cannot be reversed - backup is essential |
| 189 | + |
| 190 | +## Success Criteria |
| 191 | + |
| 192 | +✅ Application deploys successfully |
| 193 | +✅ No errors in Heroku logs |
| 194 | +✅ Website loads at https://python.ie |
| 195 | +✅ Migration 0010_remove_speakers_tables shows as applied |
| 196 | +✅ No speakers_* tables exist in database |
| 197 | +✅ Admin interface works correctly |
| 198 | + |
| 199 | +## Support |
| 200 | + |
| 201 | +If you encounter issues during deployment: |
| 202 | + |
| 203 | +1. Check Heroku logs: `task heroku:logs` |
| 204 | +2. Verify migration status: `heroku run python pythonie/manage.py showmigrations` |
| 205 | +3. Restore from backup if needed |
| 206 | +4. Contact the development team |
| 207 | + |
| 208 | +--- |
| 209 | + |
| 210 | +**Created**: 2026-01-11 |
| 211 | +**PR**: #161 |
| 212 | +**Migration**: `core.0010_remove_speakers_tables` |
0 commit comments