2

I've been using Flask-Migrate incorrectly. Between two environments I have independently created the migrations folder, and added the migrations folder to the .gitignore file.

This has recently caused problems because I would like to interact with Alembic migrations directly, and track those changes in github.

This means I have forked my production flask app, and now track the migrations folder removing its entry in my .gitignore file. I pulled this branch to my local and destroyed my local db. I ran the tracked migrations and it seems to work.

I'm wondering between two environments, how does flask migrate track what the current revision id is? Suppose I create and run two migrations on my local, and push the migrations folder. How will Flask migrate track these two revisions, and run these on Production, when I run db upgrade on production?

JZ.
  • 21,147
  • 32
  • 115
  • 192

1 Answers1

2

Alembic (the engine behind Flask-Migrate) will insert a little table in your database called alembic_version. It writes the current revision of the database in this table. Here is a dump of this table in one of my databases:

mydb=# select * from alembic_version;
 version_num
--------------
 36e0d1f0d589
(1 row)

When you run an upgrade it will know from where to start upgrading by reading the current revision from this table.

Good question!

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152