Automatically check and run pending database migrations when the application starts up, eliminating the need to manually run migrations after git pull.
- Safety: Only run in production mode with explicit opt-in
- Reliability: Use existing migration infrastructure with locking
- Visibility: Clear logging of migration activity
- Graceful Handling: Don't crash app if migrations fail
Add new environment variable:
AUTO_MIGRATE_ON_STARTUP=true/false(default: false)- Only active when
PRODUCTION_MODE=1
Location: app.py - Add to application startup sequence
Process:
- Check if auto-migration is enabled
- Import existing migration system
- Check for pending migrations
- Run migrations if needed
- Log results
Use existing components:
app_helpers/utils/enhanced_migration.py- Migration management- Existing migration lock system
- Dependency resolution and verification
- Log migration failures but don't crash app
- Provide clear error messages
- Respect migration lock timeouts
app.py- Add startup migration check (10-15 lines)CLAUDE.md- Document new environment variable
- Add environment variable check
- Import migration utilities
- Add migration check to startup sequence
- Add appropriate logging
- Handle errors gracefully
- Explicit Opt-in: Requires both
PRODUCTION_MODE=1andAUTO_MIGRATE_ON_STARTUP=true - Existing Safeguards: Leverages migration locking and verification
- Non-blocking: App continues even if migrations fail
- Logging: Clear visibility into migration activity
- Developer Experience: No need to remember manual migration steps
- Deployment Safety: Automatic schema updates on deployment
- Consistency: Always run latest migrations when app starts
- Integration: Works with existing migration system
# Enable auto-migration
export PRODUCTION_MODE=1
export AUTO_MIGRATE_ON_STARTUP=true
# Start application (migrations run automatically)
./thywill startIf issues arise, simply set AUTO_MIGRATE_ON_STARTUP=false or remove the environment variable. The app will start normally without running migrations.