DB Migration workflow

Flask-Migrate is an extension that handles SQLAlchemy database migrations for Flask applications using Alembic. The database operations are made available through the Flask command-line interface or through the Flask-Script extension.

Full list of migration commands and flask-migrate documents can be found here.

Initialize migration repository

$ flask db init

Create migration

$ flask db migrate -m "here comes migration message" 

This command creates a python script that describe what changes will be done to our db.

Apply migration:

$ flask db upgrade 

Rollback migration (downgrade)

$ flask db downgrade 

All migration commands preserve data in the DB.

List migration history

$ flask db history 

Check current migration

$ flask db current