Performance: Database migration in deployment
This affects the deployment speed and application startup time during updates, impacting user experience and downtime.
def deploy(): # Run migrations as a separate step before or after deployment asynchronously # or during maintenance window run_migrations_async() app.run()
from flask_migrate import upgrade def deploy(): upgrade() # runs migrations synchronously during app startup app.run()
| Pattern | Blocking Deployment | User Downtime | Startup Delay | Verdict |
|---|---|---|---|---|
| Synchronous migration during app start | Yes | High | Long (seconds to minutes) | [X] Bad |
| Asynchronous or pre-deployment migration | No | Low | Minimal | [OK] Good |
flask db init command creates the migration folder and scripts for the first time.migrate creates migration files, upgrade applies them, create is invalid.flask db initflask db migrate -m "Add user table"flask db upgradeinit sets up migration scripts, migrate creates migration files, upgrade applies changes to the database.upgrade, the database schema updates to include new tables or changes.flask db migrate but see no new migration file created. What is the likely cause?flask db migrate creates migration files only if there are schema changes detected.flask db migrate describing changes, then apply them with flask db upgrade.Pass the test and this pattern moves unknown