Skip to content

Commit adfb654

Browse files
committed
🛠️ feat: add automated Heroku-24 migration script (#180)
Add automated migration script to handle Heroku-22 to Heroku-24 upgrade: - Add scripts/migrate-heroku-24.sh: Automated migration script - Handles migration with safety checks and backups - Includes automatic rollback capability - Performs smoke tests after migration - Detailed logging and error handling - Add scripts/README-heroku-migration.md: Complete documentation - Usage instructions and examples - Features and safety mechanisms - Troubleshooting guide - Post-migration monitoring instructions Features: ✅ Automatic database and config backups ✅ Maintenance mode handling ✅ Built-in smoke tests ✅ One-command rollback ✅ Confirmation prompts ✅ Detailed logging Related to #180
1 parent 25078af commit adfb654

File tree

2 files changed

+724
-0
lines changed

2 files changed

+724
-0
lines changed

scripts/README-heroku-migration.md

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
# Heroku-24 Migration Script
2+
3+
Automated script to migrate the Python Ireland website from Heroku-22 to Heroku-24 stack, with built-in rollback capabilities.
4+
5+
## Prerequisites
6+
7+
- Heroku CLI installed and authenticated (`heroku login`)
8+
- Git repository with `heroku` remote configured
9+
- Access to the `pythonie` Heroku app
10+
- HEROKU_APP environment variable set (or defaults to `pythonie`)
11+
12+
## Quick Start
13+
14+
### 1. Check Current Status
15+
16+
```bash
17+
./scripts/migrate-heroku-24.sh status
18+
```
19+
20+
This shows:
21+
- Current stack (heroku-22 or heroku-24)
22+
- Available stacks
23+
- PostgreSQL version and status
24+
- Migration readiness
25+
26+
### 2. Run Migration
27+
28+
```bash
29+
./scripts/migrate-heroku-24.sh migrate
30+
```
31+
32+
**What happens:**
33+
1. Creates database and config backups
34+
2. Enables maintenance mode (~5-10 min downtime)
35+
3. Upgrades stack to heroku-24
36+
4. Redeploys the application
37+
5. Runs smoke tests (homepage, admin, logs)
38+
6. Disables maintenance mode
39+
7. Reports success or offers rollback
40+
41+
### 3. Rollback (if needed)
42+
43+
```bash
44+
./scripts/migrate-heroku-24.sh rollback
45+
```
46+
47+
**What happens:**
48+
1. Enables maintenance mode
49+
2. Rolls back to previous Heroku release
50+
3. Reverts stack to heroku-22
51+
4. Redeploys the application
52+
5. Disables maintenance mode
53+
54+
## Features
55+
56+
### ✅ Safety Features
57+
58+
- **Automatic backups**: Database and config saved before migration
59+
- **Confirmation prompts**: Requires explicit confirmation before proceeding
60+
- **Maintenance mode**: App goes into maintenance during migration
61+
- **Smoke tests**: Automatic verification after migration
62+
- **Error handling**: Stops on errors, offers rollback option
63+
- **Detailed logging**: All actions logged to timestamped file
64+
65+
### 📋 Migration Steps
66+
67+
The script performs these steps automatically:
68+
69+
1. **Setup & Verification**
70+
- Checks Heroku CLI is installed
71+
- Verifies authentication
72+
- Confirms app exists
73+
74+
2. **Backup Phase**
75+
- Creates PostgreSQL backup
76+
- Saves configuration to file
77+
- Downloads backup locally
78+
79+
3. **Migration Phase**
80+
- Enables maintenance mode
81+
- Creates final backup
82+
- Upgrades stack to heroku-24
83+
- Redeploys application
84+
85+
4. **Verification Phase**
86+
- Waits for deployment stabilization
87+
- Tests homepage accessibility
88+
- Tests admin accessibility
89+
- Checks logs for errors
90+
91+
5. **Completion**
92+
- Disables maintenance mode
93+
- Reports success
94+
- Provides monitoring instructions
95+
96+
## Usage Examples
97+
98+
### Basic migration (uses default app: pythonie)
99+
100+
```bash
101+
./scripts/migrate-heroku-24.sh migrate
102+
```
103+
104+
### Migration for different app
105+
106+
```bash
107+
HEROKU_APP=my-other-app ./scripts/migrate-heroku-24.sh migrate
108+
```
109+
110+
### Check status before migration
111+
112+
```bash
113+
./scripts/migrate-heroku-24.sh status
114+
```
115+
116+
### Emergency rollback
117+
118+
```bash
119+
./scripts/migrate-heroku-24.sh rollback
120+
```
121+
122+
## Output & Logging
123+
124+
All actions are logged to:
125+
```
126+
/tmp/heroku-migration-backups/migration-YYYYMMDD-HHMMSS.log
127+
```
128+
129+
Backups are saved to:
130+
```
131+
/tmp/heroku-migration-backups/backup-YYYYMMDD-HHMMSS.dump
132+
/tmp/heroku-migration-backups/config-YYYYMMDD-HHMMSS.env
133+
```
134+
135+
## What to Monitor After Migration
136+
137+
### Immediate (0-1 hour)
138+
139+
```bash
140+
# Watch logs in real-time
141+
heroku logs --tail -a pythonie
142+
143+
# Check dyno status
144+
heroku ps -a pythonie
145+
146+
# Verify stack
147+
heroku stack -a pythonie
148+
```
149+
150+
### Short-term (1-24 hours)
151+
152+
```bash
153+
# Check metrics
154+
heroku metrics -a pythonie
155+
156+
# Review error rates
157+
heroku logs -a pythonie | grep -i error
158+
159+
# Test critical features
160+
# - Homepage: https://python.ie
161+
# - Admin: https://python.ie/admin/
162+
# - Content pages
163+
```
164+
165+
### Medium-term (24-48 hours)
166+
167+
- Monitor error logs daily
168+
- Check performance metrics
169+
- Verify all business features
170+
- Review CPU/memory usage
171+
172+
## Troubleshooting
173+
174+
### Migration fails during redeploy
175+
176+
The script will automatically offer to rollback. Accept the rollback prompt.
177+
178+
### Smoke tests fail
179+
180+
The script will ask if you want to rollback. You can:
181+
- Accept rollback (recommended)
182+
- Decline and debug manually (app stays in maintenance mode)
183+
184+
### Manual rollback needed
185+
186+
```bash
187+
# Enable maintenance
188+
heroku maintenance:on -a pythonie
189+
190+
# Rollback release
191+
heroku rollback -a pythonie
192+
193+
# Revert stack
194+
heroku stack:set heroku-22 -a pythonie
195+
git push heroku master
196+
197+
# Disable maintenance
198+
heroku maintenance:off -a pythonie
199+
```
200+
201+
### App won't start after migration
202+
203+
1. Check build logs:
204+
```bash
205+
heroku logs --tail -a pythonie
206+
```
207+
208+
2. Check for migration errors:
209+
```bash
210+
heroku run python pythonie/manage.py showmigrations -a pythonie
211+
```
212+
213+
3. Rollback if needed:
214+
```bash
215+
./scripts/migrate-heroku-24.sh rollback
216+
```
217+
218+
## Exit Codes
219+
220+
- `0` - Success
221+
- `1` - Error occurred (check logs)
222+
223+
## Environment Variables
224+
225+
- `HEROKU_APP` - Heroku application name (default: `pythonie`)
226+
227+
## Security Notes
228+
229+
- Backups contain sensitive data - stored in `/tmp` (auto-cleaned on reboot)
230+
- Config files contain secrets - handle with care
231+
- Clean up old backups regularly
232+
233+
## Support
234+
235+
For issues or questions:
236+
- See full test documentation: `docs/heroku-24-migration-tests.md`
237+
- GitHub issue: #180
238+
- Heroku support: https://help.heroku.com/
239+
240+
## Related Documentation
241+
242+
- [Heroku-24 Stack](https://devcenter.heroku.com/articles/heroku-24-stack)
243+
- [Stack Upgrades](https://devcenter.heroku.com/articles/upgrading-to-the-latest-stack)
244+
- [Python 3.13 on Heroku](https://devcenter.heroku.com/articles/python-support)

0 commit comments

Comments
 (0)